Skip to content

Commit

Permalink
Use server-side apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Gchbg committed Mar 28, 2024
1 parent 6a361e7 commit 96350d0
Show file tree
Hide file tree
Showing 39 changed files with 18,317 additions and 198 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ COPY go.sum go.sum
RUN go mod download

COPY api/ api/
COPY client/ client/
COPY cmd/ cmd/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o metal cmd/main.go
Expand Down
48 changes: 13 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
IMG ?= controller:latest
ENVTEST_K8S_VERSION = 1.29.0

ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

CONTAINER_TOOL ?= docker

SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

Expand Down Expand Up @@ -36,73 +33,54 @@ help: ## Display this help.

.PHONY: manifests
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
@go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
@go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
@internal/tools/generate.sh

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
@go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
@go vet ./...

.PHONY: test
test: manifests generate fmt vet ## Run tests.
KUBEBUILDER_ASSETS="$(shell go run sigs.k8s.io/controller-runtime/tools/setup-envtest use $(ENVTEST_K8S_VERSION) -p path)" go test $$(go list ./... | grep -v /e2e)
@KUBEBUILDER_ASSETS="$(shell go run sigs.k8s.io/controller-runtime/tools/setup-envtest use -p path)" go test $$(go list ./... | grep -v /e2e)

.PHONY: test-e2e
test-e2e: ## Run the e2e tests against a Kind k8s instance that is spun up.
go test ./test/e2e/ -v -ginkgo.v
@go test ./test/e2e/ -v -ginkgo.v

.PHONY: lint
lint: ## Run golangci-lint linter & yamllint.
go run github.com/golangci/golangci-lint/cmd/golangci-lint run
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run

.PHONY: addlicense
addlicense: ## Add license headers to all go files.
find . -name '*.go' -exec go run github.com/google/addlicense -f hack/license-header.txt {} +
@find . -name '*.go' -exec go run github.com/google/addlicense -f hack/license-header.txt {} +

.PHONY: checklicense
checklicense: ## Check that every file has a license header present.
find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'IronCore authors' {} +
@find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'IronCore authors' {} +

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o metal cmd/main.go
@go build -o metal cmd/main.go

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .
@docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG}

PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
$(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

.PHONY: build-installer
build-installer: manifests generate ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
@if [ -d "config/crd" ]; then \
go run sigs.k8s.io/kustomize/kustomize/v5 build config/crd > dist/install.yaml; \
fi
echo "---" >> dist/install.yaml
cd config/manager && go run sigs.k8s.io/kustomize/kustomize/v5 edit set image controller=${IMG}
go run sigs.k8s.io/kustomize/kustomize/v5 build config/default >> dist/install.yaml
@docker push ${IMG}

##@ Deployment

Expand Down
13 changes: 11 additions & 2 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Prefix struct {
netip.Prefix `json:"-"`
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) UnmarshalJSON(b []byte) error {
if len(b) == 4 && string(b) == "null" {
p.Prefix = netip.Prefix{}
Expand All @@ -34,6 +35,7 @@ func (p *Prefix) UnmarshalJSON(b []byte) error {
return nil
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) MarshalJSON() ([]byte, error) {
if p.IsZero() {
return []byte("null"), nil
Expand All @@ -42,6 +44,7 @@ func (p *Prefix) MarshalJSON() ([]byte, error) {
return json.Marshal(p.String())
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) ToUnstructured() interface{} {
if p.IsZero() {
return nil
Expand All @@ -50,26 +53,32 @@ func (p *Prefix) ToUnstructured() interface{} {
return p.String()
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) DeepCopyInto(out *Prefix) {
*out = *p
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) DeepCopy() *Prefix {
return &Prefix{p.Prefix}
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) IsValid() bool {
return p != nil && p.Prefix.IsValid()
}

//goland:noinspection GoMixedReceiverTypes
func (p *Prefix) IsZero() bool {
return p == nil || !p.Prefix.IsValid()
}

func (p *Prefix) OpenAPISchemaType() []string {
//goland:noinspection GoMixedReceiverTypes
func (p Prefix) OpenAPISchemaType() []string {
return []string{"string"}
}

func (p *Prefix) OpenAPISchemaFormat() string {
//goland:noinspection GoMixedReceiverTypes
func (p Prefix) OpenAPISchemaFormat() string {
return "prefix"
}
8 changes: 8 additions & 0 deletions api/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +groupName=metal.ironcore.dev

package v1alpha1
3 changes: 2 additions & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (

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

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
27 changes: 7 additions & 20 deletions api/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
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.
*/
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

Expand All @@ -22,10 +9,10 @@ import (
)

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

// MachineSpec defines the desired state of Machine
Expand All @@ -47,7 +34,7 @@ type MachineSpec struct {
ASN string `json:"asn,omitempty"`

//+optional
Power Power `json:"power,omitempty"` // todo revisit whether optional
Power Power `json:"power,omitempty"` // TODO: Revisit whether this is really optional.

//+optional
LocatorLED LocatorLED `json:"locatorLED,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/machineclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type MachineClaimSpec struct {
IgnitionSecretRef *v1.LocalObjectReference `json:"ignitionSecretRef,omitempty"`

//+optional
NetworkInterfaces []MachineClaimNetworkInterface `json:"networkInterfaces,omitempty"` // todo is it optional?
NetworkInterfaces []MachineClaimNetworkInterface `json:"networkInterfaces,omitempty"` // TODO: Revisit whether this is really optional.
}

type MachineClaimNetworkInterface struct {
Expand Down
5 changes: 2 additions & 3 deletions api/v1alpha1/oob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
)

const (
OOBOperationKeyName string = "oob.metal.ironcore.dev/operation"
OOBOperationReset string = "Reset" // TODO: check proper names here
OOBOperationForceReset string = "ForceReset"
OOBOperationKeyName string = "oob.metal.ironcore.dev/operation"
OOBOperationRestart string = "Restart"
)

// OOBSpec defines the desired state of OOB
Expand Down
39 changes: 39 additions & 0 deletions client/applyconfiguration/api/v1alpha1/consoleprotocol.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96350d0

Please sign in to comment.