Skip to content

Commit

Permalink
Add CRD definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gchbg committed Mar 19, 2024
1 parent 843da7f commit c75d7fd
Show file tree
Hide file tree
Showing 46 changed files with 3,035 additions and 155 deletions.
2 changes: 2 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Disclaimer: The code in this project may include calls to APIs ("API Calls") of

Files:
.github/*
api/*
cmd/*
config/*
hack/*
internal/*
test/*
.dockerignore
.gitignore
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

#COPY api/ api/
COPY api/ api/
COPY cmd/ cmd/
#COPY internal/ internal/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o metal cmd/main.go

FROM debian:bookworm-20240311-slim
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e)


.PHONY: test-e2e
Expand Down
38 changes: 34 additions & 4 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: ironcore.dev
layout:
- go.kubebuilder.io/v4
projectName: metal
repo: github.com/ironcore-dev/metal
resources:
- api:
crdVersion: v1
controller: true
domain: ironcore.dev
group: metal
kind: Machine
path: github.com/ironcore-dev/metal/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: ironcore.dev
group: metal
kind: MachineClaim
path: github.com/ironcore-dev/metal/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: ironcore.dev
group: metal
kind: OOB
path: github.com/ironcore-dev/metal/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
controller: true
domain: ironcore.dev
group: metal
kind: OOBSecret
path: github.com/ironcore-dev/metal/api/v1alpha1
version: v1alpha1
version: "3"
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
# ironcore-dev Repository Template

Default templates for ironcore-dev open source repositories, including LICENSE, .reuse/dep5, Code of Conduct, etc... All repositories on github.com/SAP will be created based on this template.

## To-Do

In case you are the maintainer of a new SAP open source project, these are the steps to do with the template files:

- Check if the default license (Apache 2.0) also applies to your project. A license change should only be required in exceptional cases. If this is the case, please change the [license file](LICENSE).
- Enter the correct metadata for the REUSE tool. See our [wiki page](https://wiki.one.int.sap/wiki/display/ospodocs/Using+the+Reuse+Tool+of+FSFE+for+Copyright+and+License+Information) for details how to do it. You can find an initial .reuse/dep5 file to build on. Please replace the parts inside the single angle quotation marks < > by the specific information for your repository and be sure to run the REUSE tool to validate that the metadata is correct.
- Adjust the contribution guidelines (e.g. add coding style guidelines, pull request checklists, different license if needed etc.)
- Add information about your project to this README (name, description, requirements etc). Especially take care for the <your-project> placeholders - those ones need to be replaced with your project name. See the sections below the horizontal line and [our guidelines on our wiki page](https://wiki.one.int.sap/wiki/pages/viewpage.action?pageId=3564976048#GuidelinesforGitHubHealthfiles(Readme,Contributing,CodeofConduct)-Readme.md) what is required and recommended.
- Remove all content in this README above and including the horizontal line ;)

***

# Our new open source project
# Metal

## About this project

*Insert a short description of your project here...*

## Requirements and Setup

*Insert a short description what is required to get your project running...*

## Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/ironcore-dev/<your-project>/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
Expand Down
72 changes: 72 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package v1alpha1

import (
"encoding/json"
"net/netip"
)

type Prefix struct {
netip.Prefix `json:"-"`
}

func (p *Prefix) UnmarshalJSON(b []byte) error {
if len(b) == 4 && string(b) == "null" {
p.Prefix = netip.Prefix{}
return nil
}

var str string
err := json.Unmarshal(b, &str)
if err != nil {
return err
}

var pr netip.Prefix
pr, err = netip.ParsePrefix(str)
if err != nil {
return err
}

p.Prefix = pr
return nil
}

func (p *Prefix) MarshalJSON() ([]byte, error) {
if p.IsZero() {
return []byte("null"), nil
}

return json.Marshal(p.String())
}

func (p *Prefix) ToUnstructured() interface{} {
if p.IsZero() {
return nil
}

return p.String()
}

func (p *Prefix) DeepCopyInto(out *Prefix) {
*out = *p
}

func (p *Prefix) DeepCopy() *Prefix {
return &Prefix{p.Prefix}
}

func (p *Prefix) IsValid() bool {
return p != nil && p.Prefix.IsValid()
}

func (p *Prefix) IsZero() bool {
return p == nil || !p.Prefix.IsValid()
}

func (p *Prefix) OpenAPISchemaType() []string {
return []string{"string"}
}

func (p *Prefix) OpenAPISchemaFormat() string {
return "prefix"
}
36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the metal v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=metal.ironcore.dev
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "metal.ironcore.dev", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
155 changes: 155 additions & 0 deletions api/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
MachineOperationKeyName string = "machine.metal.ironcore.dev/operation"
MachineOperationReboot string = "Reboot"
MachineOperationReset string = "Reset"
MachineOperationForceOff string = "ForceOff"
)

// MachineSpec defines the desired state of Machine
type MachineSpec struct {
UUID string `json:"uuid"` //todo valiation

OOBRef v1.LocalObjectReference `json:"oobRef"`

InventoryRef v1.LocalObjectReference `json:"inventoryRef"`

//+optional
MachineClaimRef *v1.ObjectReference `json:"machineClaimRef,omitempty"`

//+optional
LoopbackAddressRef *v1.LocalObjectReference `json:"loopbackAddressRef,omitempty"`

//+optional
ASN string `json:"asn,omitempty"`

//+optional
Power Power `json:"power,omitempty"` // todo revisit whether optional

//+optional
LocatorLED LocatorLED `json:"locatorLED,omitempty"`
}

type Power string

const (
PowerOn Power = "On"
PowerOff Power = "Off"
)

type LocatorLED string

const (
LocatorLEDOn Power = "On"
LocatorLEDOff Power = "Off"
LocatorLEDBlinking Power = "Blinking"
)

// MachineStatus defines the observed state of Machine
type MachineStatus struct {
//+optional
Manufacturer string `json:"manufacturer,omitempty"`

//+optional
SKU string `json:"sku,omitempty"`

//+optional
SerialNumber string `json:"serialNumber,omitempty"`

//+optional
Power Power `json:"power,omitempty"`

//+optional
LocatorLED LocatorLED `json:"locatorLED,omitempty"`

//+optional
ShutdownDeadline *metav1.Time `json:"shutdownDeadline,omitempty"`

//+optional
NetworkInterfaces []MachineNetworkInterface `json:"networkInterfaces"`

//+optional
State MachineState `json:"state,omitempty"`

//+patchStrategy=merge
//+patchMergeKey=type
//+optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

type MachineNetworkInterface struct {
Name string `json:"name"`

//+kubebuilder:validation:Pattern=`^[0-9a-f]{12}$`
MacAddress string `json:"macAddress"`

//+optional
IPRef *v1.LocalObjectReference `json:"IPRef,omitempty"`

//+optional
SwitchRef *v1.LocalObjectReference `json:"switchRef,omitempty"`
}

type MachineState string

const (
MachineStateReady MachineState = "Ready"
MachineStateError MachineState = "Error"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="UUID",type=string,JSONPath=`.status.uuid`
//+kubebuilder:printcolumn:name="Manufacturer",type=string,JSONPath=`.status.manufacturer`
//+kubebuilder:printcolumn:name="SKU",type=string,JSONPath=`.status.sku`,priority=100
//+kubebuilder:printcolumn:name="SerialNumber",type=string,JSONPath=`.status.serialNumber`,priority=100
//+kubebuilder:printcolumn:name="Power",type=string,JSONPath=`.status.power`
//+kubebuilder:printcolumn:name="LocatorLED",type=string,JSONPath=`.status.locatorLED`,priority=100
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimeStamp`
// +genclient

// Machine is the Schema for the machines API
type Machine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MachineSpec `json:"spec,omitempty"`
Status MachineStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// MachineList contains a list of Machine
type MachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Machine `json:"items"`
}

func init() {
SchemeBuilder.Register(&Machine{}, &MachineList{})
}
Loading

0 comments on commit c75d7fd

Please sign in to comment.