Skip to content

Commit

Permalink
Fix device admission, generate applyconfigurations (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus authored Nov 17, 2022
1 parent bddbf8c commit d0a906f
Show file tree
Hide file tree
Showing 253 changed files with 13,732 additions and 572 deletions.
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./onmetal-controller-manager/controllers/...;./api/..." output:rbac:artifacts:config=config/controller/rbac

.PHONY: generate
generate: vgopath deepcopy-gen client-gen lister-gen informer-gen defaulter-gen conversion-gen openapi-gen
go mod download
generate: vgopath models-schema deepcopy-gen client-gen lister-gen informer-gen defaulter-gen conversion-gen openapi-gen applyconfiguration-gen
VGOPATH=$(VGOPATH) \
MODELS_SCHEMA=$(MODELS_SCHEMA) \
DEEPCOPY_GEN=$(DEEPCOPY_GEN) \
CLIENT_GEN=$(CLIENT_GEN) \
LISTER_GEN=$(LISTER_GEN) \
INFORMER_GEN=$(INFORMER_GEN) \
DEFAULTER_GEN=$(DEFAULTER_GEN) \
CONVERSION_GEN=$(CONVERSION_GEN) \
OPENAPI_GEN=$(OPENAPI_GEN) \
APPLYCONFIGURATION_GEN=$(APPLYCONFIGURATION_GEN) \
./hack/update-codegen.sh

.PHONY: fmt
Expand All @@ -75,6 +76,7 @@ lint: ## Run golangci-lint on the code.

.PHONY: clean
clean: ## Clean any artifacts that can be regenerated.
rm -rf client-go/applyconfigurations
rm -rf client-go/informers
rm -rf client-go/listers
rm -rf client-go/onmetalapi
Expand All @@ -85,7 +87,7 @@ add-license: addlicense ## Add license headers to all go files.
find . -name '*.go' -exec $(ADDLICENSE) -c 'OnMetal authors' {} +

.PHONY: check-license
check-license: ## Check that every file has a license header present.
check-license: addlicense ## Check that every file has a license header present.
find . -name '*.go' -exec $(ADDLICENSE) -check -c 'OnMetal authors' {} +

.PHONY: check
Expand Down Expand Up @@ -245,9 +247,11 @@ INFORMER_GEN ?= $(LOCALBIN)/informer-gen
DEFAULTER_GEN ?= $(LOCALBIN)/defaulter-gen
CONVERSION_GEN ?= $(LOCALBIN)/conversion-gen
OPENAPI_GEN ?= $(LOCALBIN)/openapi-gen
APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen
VGOPATH ?= $(LOCALBIN)/vgopath
GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs
ADDLICENSE ?= $(LOCALBIN)/addlicense
MODELS_SCHEMA ?= $(LOCALBIN)/models-schema

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
Expand Down Expand Up @@ -308,6 +312,11 @@ openapi-gen: $(OPENAPI_GEN) ## Download openapi-gen locally if necessary.
$(OPENAPI_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/openapi-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/openapi-gen@$(CODE_GENERATOR_VERSION)

.PHONY: applyconfiguration-gen
applyconfiguration-gen: $(APPLYCONFIGURATION_GEN) ## Download applyconfiguration-gen locally if necessary.
$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/applyconfiguration-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODE_GENERATOR_VERSION)

.PHONY: vgopath
vgopath: $(VGOPATH) ## Download vgopath locally if necessary.
$(VGOPATH): $(LOCALBIN)
Expand All @@ -331,5 +340,10 @@ $(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN)
.PHONY: addlicense
addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary.
$(ADDLICENSE): $(LOCALBIN)
test-s $(LOCALBIN)/addlicense || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION)
test -s $(LOCALBIN)/addlicense || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION)

.PHONY: models-schema
models-schema: $(MODELS_SCHEMA) ## Install models-schema locally if necessary.
$(MODELS_SCHEMA): $(LOCALBIN)
test -s $(LOCALBIN)/models-schema || GOBIN=$(LOCALBIN) go install github.com/onmetal/onmetal-api/models-schema

13 changes: 9 additions & 4 deletions api/common/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ const (

// ConfigMapKeySelector is a reference to a specific 'key' within a ConfigMap resource.
// In some instances, `key` is a required field.
// +structType=atomic
type ConfigMapKeySelector struct {
// The name of the ConfigMap resource being referred to.
corev1.LocalObjectReference `json:",inline"`
// Name of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Name string `json:"name,omitempty"`
// The key of the entry in the ConfigMap resource's `data` field to be used.
// Some instances of this field may be defaulted, in others it may be
// required.
Expand All @@ -55,9 +57,11 @@ type ConfigMapKeySelector struct {

// SecretKeySelector is a reference to a specific 'key' within a Secret resource.
// In some instances, `key` is a required field.
// +structType=atomic
type SecretKeySelector struct {
// The name of the Secret resource being referred to.
corev1.LocalObjectReference `json:",inline"`
// Name of the referent.
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
Name string `json:"name,omitempty"`
// The key of the entry in the Secret resource's `data` field to be used.
// Some instances of this field may be defaulted, in others it may be
// required.
Expand All @@ -66,6 +70,7 @@ type SecretKeySelector struct {
}

// LocalUIDReference is a reference to another entity including its UID
// +structType=atomic
type LocalUIDReference struct {
// Name is the name of the referenced entity.
Name string `json:"name"`
Expand Down
32 changes: 32 additions & 0 deletions api/common/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021 by the OnMetal authors.
*
* 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 common v1alpha1 API group
// +groupName=common.api.onmetal.de
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "common.api.onmetal.de", Version: "v1alpha1"}
)

func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
4 changes: 1 addition & 3 deletions api/common/v1alpha1/zz_generated.deepcopy.go

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

22 changes: 16 additions & 6 deletions api/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ type MachineSpec struct {
// ImagePullSecretRef is an optional secret for pulling the image of a machine.
ImagePullSecretRef *corev1.LocalObjectReference `json:"imagePullSecret,omitempty"`
// NetworkInterfaces define a list of network interfaces present on the machine
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
// Volumes are volumes attached to this machine.
Volumes []Volume `json:"volumes,omitempty"`
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
Volumes []Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
// IgnitionRef is a reference to a secret containing the ignition YAML for the machine to boot up.
// If key is empty, DefaultIgnitionKey will be used as fallback.
IgnitionRef *commonv1alpha1.SecretKeySelector `json:"ignitionRef,omitempty"`
// EFIVars are variables to pass to EFI while booting up.
EFIVars []EFIVar `json:"efiVars,omitempty"`
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
EFIVars []EFIVar `json:"efiVars,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
// Tolerations define tolerations the Machine has. Only MachinePools whose taints
// covered by Tolerations will be considered to run the Machine.
Tolerations []commonv1alpha1.Toleration `json:"tolerations,omitempty"`
Expand Down Expand Up @@ -85,9 +94,10 @@ type NetworkInterfaceSource struct {
type Volume struct {
// Name is the name of the Volume
Name string `json:"name"`
// Device is the device name where the volume should be attached. If empty,
// an unused device name will be determined if possible.
Device string `json:"device,omitempty"`
// Device is the device name where the volume should be attached.
// Pointer to distinguish between explicit zero and not specified.
// If empty, an unused device name will be determined if possible.
Device *string `json:"device,omitempty"`
// VolumeSource is the source where the storage for the Volume resides at.
VolumeSource `json:",inline"`
}
Expand Down
3 changes: 1 addition & 2 deletions api/compute/v1alpha1/machineclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ var (

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genClient:nonNamespaced
// +genClient:noStatus
// +genclient:nonNamespaced

// MachineClass is the Schema for the machineclasses API
type MachineClass struct {
Expand Down
2 changes: 1 addition & 1 deletion api/compute/v1alpha1/machinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const (

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genClient:nonNamespaced
// +genclient:nonNamespaced

// MachinePool is the Schema for the machinepools API
type MachinePool struct {
Expand Down
7 changes: 6 additions & 1 deletion api/compute/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 4 additions & 1 deletion api/networking/v1alpha1/natgateway_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ type NATGatewaySpec struct {
// IPFamilies are the ip families the load balancer should have.
IPFamilies []corev1.IPFamily `json:"ipFamilies"`
// IPs are the ips the NAT gateway should allocate.
IPs []NATGatewayIP `json:"ips"`
// +optional
// +patchMergeKey=name
// +patchStrategy=merge,retainKeys
IPs []NATGatewayIP `json:"ips" patchStrategy:"merge,retainKeys" patchMergeKey:"name"`
// NetworkRef is the Network this NATGateway should belong to.
NetworkRef corev1.LocalObjectReference `json:"networkRef"`
// NetworkInterfaceSelector defines the NetworkInterfaces
Expand Down
6 changes: 5 additions & 1 deletion api/networking/v1alpha1/natgatewayrouting_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1alpha1
import (
commonv1alpha1 "github.com/onmetal/onmetal-api/api/common/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

// +genclient
Expand All @@ -37,7 +38,10 @@ type NATGatewayRouting struct {
}

type NATGatewayDestination struct {
commonv1alpha1.LocalUIDReference `json:",inline"`
// Name is the name of the referenced entity.
Name string `json:"name"`
// UID is the UID of the referenced entity.
UID types.UID `json:"uid"`
// IPs are the nat gateway ips used.
IPs []NATGatewayDestinationIP `json:"ips"`
}
Expand Down
3 changes: 1 addition & 2 deletions api/networking/v1alpha1/zz_generated.deepcopy.go

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

1 change: 0 additions & 1 deletion api/storage/v1alpha1/volumeclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var (
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genclient:nonNamespaced
// +genclient:noStatus

// VolumeClass is the Schema for the volumeclasses API
type VolumeClass struct {
Expand Down
2 changes: 1 addition & 1 deletion api/storage/v1alpha1/zz_generated.deepcopy.go

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

51 changes: 51 additions & 0 deletions client-go/applyconfigurations/common/v1alpha1/localuidreference.go

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

Loading

0 comments on commit d0a906f

Please sign in to comment.