diff --git a/.github/workflows/check-codegen.yml b/.github/workflows/check-codegen.yml index 7f062a8b1..7cc1741e9 100644 --- a/.github/workflows/check-codegen.yml +++ b/.github/workflows/check-codegen.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.17' + go-version: '1.19' - name: Run make generate run: make generate - name: Compare the expected and actual generated/* directories diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5dfaa4392..9a36e80e0 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,8 +13,8 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: '1.17' + go-version: '1.19' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.43.0 + version: v1.48.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 418ebf128..02f5982db 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,7 @@ name: Pull Request Code test on: - pull_request_target: + pull_request: types: [ assigned, opened, synchronize, reopened ] paths-ignore: - 'docs/**' @@ -13,9 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - with: - ref: ${{ github.event.pull_request.head.sha }} - uses: actions/setup-go@v3 with: - go-version: '1.17' + go-version: '1.19' - run: make test diff --git a/Dockerfile b/Dockerfile index 48afa12f4..556a83b15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM --platform=$BUILDPLATFORM golang:1.18 as builder +FROM --platform=$BUILDPLATFORM golang:1.19 as builder WORKDIR /workspace # Copy the Go Modules manifests diff --git a/apis/common/v1alpha1/common_types.go b/apis/common/v1alpha1/common_types.go index 05ec1472a..83b774f8b 100644 --- a/apis/common/v1alpha1/common_types.go +++ b/apis/common/v1alpha1/common_types.go @@ -58,7 +58,7 @@ type LocalUIDReference struct { } // IP is an IP address. -//+kubebuilder:validation:Type=string +// +kubebuilder:validation:Type=string type IP struct { netaddr.IP `json:"-"` } @@ -254,8 +254,8 @@ func EqualIPRanges(a, b IPRange) bool { } // IPPrefix represents a network prefix. -//+kubebuilder:validation:Type=string -//+nullable +// +kubebuilder:validation:Type=string +// +nullable type IPPrefix struct { netaddr.IPPrefix `json:"-"` } @@ -375,7 +375,7 @@ type Taint struct { Effect TaintEffect `json:"effect"` } -//+kubebuilder:validation:Enum=NoSchedule +// +kubebuilder:validation:Enum=NoSchedule type TaintEffect string const ( @@ -408,11 +408,14 @@ type Toleration struct { // ToleratesTaint checks if the toleration tolerates the taint. // The matching follows the rules below: // (1) Empty toleration.effect means to match all taint effects, -// otherwise taint effect must equal to toleration.effect. +// +// otherwise taint effect must equal to toleration.effect. +// // (2) If toleration.operator is 'Exists', it means to match all taint values. // (3) Empty toleration.key means to match all taint keys. -// If toleration.key is empty, toleration.operator must be 'Exists'; -// this combination means to match all taint values and all taint keys. +// +// If toleration.key is empty, toleration.operator must be 'Exists'; +// this combination means to match all taint values and all taint keys. func (t *Toleration) ToleratesTaint(taint *Taint) bool { if len(t.Effect) > 0 && t.Effect != taint.Effect { return false @@ -433,7 +436,7 @@ func (t *Toleration) ToleratesTaint(taint *Taint) bool { } // A toleration operator is the set of operators that can be used in a toleration. -//+kubebuilder:validation:Enum=Equal;Exists +// +kubebuilder:validation:Enum=Equal;Exists type TolerationOperator string const ( diff --git a/apis/compute/machine_types.go b/apis/compute/machine_types.go index cd3a5a7d8..910442f04 100644 --- a/apis/compute/machine_types.go +++ b/apis/compute/machine_types.go @@ -167,7 +167,7 @@ type MachineStatus struct { } // MachineState is the state of a machine. -//+enum +// +enum type MachineState string const ( diff --git a/apis/compute/machinepool_types.go b/apis/compute/machinepool_types.go index d8b8f19bb..b3d11011b 100644 --- a/apis/compute/machinepool_types.go +++ b/apis/compute/machinepool_types.go @@ -110,7 +110,7 @@ type MachinePoolCondition struct { } // MachinePoolState is a state a MachinePool can be in. -//+enum +// +enum type MachinePoolState string const ( diff --git a/apis/compute/register.go b/apis/compute/register.go index 268a6593e..0392fbabd 100644 --- a/apis/compute/register.go +++ b/apis/compute/register.go @@ -15,8 +15,8 @@ */ // Package compute contains API Schema definitions for the compute internal API group -//+kubebuilder:object:generate=true -//+groupName=compute.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=compute.api.onmetal.de package compute import ( diff --git a/apis/compute/v1alpha1/machine_types.go b/apis/compute/v1alpha1/machine_types.go index e9e0f2f4f..9847eb80c 100644 --- a/apis/compute/v1alpha1/machine_types.go +++ b/apis/compute/v1alpha1/machine_types.go @@ -167,7 +167,7 @@ type MachineStatus struct { } // MachineState is the state of a machine. -//+enum +// +enum type MachineState string const ( diff --git a/apis/compute/v1alpha1/machinepool_types.go b/apis/compute/v1alpha1/machinepool_types.go index 3c5539c0d..b8c80a8e7 100644 --- a/apis/compute/v1alpha1/machinepool_types.go +++ b/apis/compute/v1alpha1/machinepool_types.go @@ -110,7 +110,7 @@ type MachinePoolCondition struct { } // MachinePoolState is a state a MachinePool can be in. -//+enum +// +enum type MachinePoolState string const ( diff --git a/apis/compute/v1alpha1/register.go b/apis/compute/v1alpha1/register.go index 5f687406a..336737106 100644 --- a/apis/compute/v1alpha1/register.go +++ b/apis/compute/v1alpha1/register.go @@ -15,8 +15,8 @@ */ // Package v1alpha1 contains API Schema definitions for the compute v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=compute.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=compute.api.onmetal.de package v1alpha1 import ( diff --git a/apis/ipam/register.go b/apis/ipam/register.go index 928a73f2e..4269bc86e 100644 --- a/apis/ipam/register.go +++ b/apis/ipam/register.go @@ -15,8 +15,8 @@ */ // Package ipam contains API Schema definitions for the ipam internal API group -//+kubebuilder:object:generate=true -//+groupName=ipam.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=ipam.api.onmetal.de package ipam import ( diff --git a/apis/ipam/v1alpha1/register.go b/apis/ipam/v1alpha1/register.go index 105df7434..194431ec4 100644 --- a/apis/ipam/v1alpha1/register.go +++ b/apis/ipam/v1alpha1/register.go @@ -15,8 +15,8 @@ */ // Package v1alpha1 contains API Schema definitions for the network v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=ipam.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=ipam.api.onmetal.de package v1alpha1 import ( diff --git a/apis/networking/register.go b/apis/networking/register.go index b0c0cf5a4..cd5cc134a 100644 --- a/apis/networking/register.go +++ b/apis/networking/register.go @@ -15,8 +15,8 @@ */ // Package networking contains API Schema definitions for the networking internal API group -//+kubebuilder:object:generate=true -//+groupName=networking.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=networking.api.onmetal.de package networking import ( diff --git a/apis/networking/v1alpha1/register.go b/apis/networking/v1alpha1/register.go index cf9bcc3a4..fc97cd2e7 100644 --- a/apis/networking/v1alpha1/register.go +++ b/apis/networking/v1alpha1/register.go @@ -15,8 +15,8 @@ */ // Package v1alpha1 contains API Schema definitions for the networking v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=networking.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=networking.api.onmetal.de package v1alpha1 import ( diff --git a/apis/storage/register.go b/apis/storage/register.go index 8923cbca8..88c920899 100644 --- a/apis/storage/register.go +++ b/apis/storage/register.go @@ -15,8 +15,8 @@ */ // Package storage contains API Schema definitions for the storage internal API group -//+kubebuilder:object:generate=true -//+groupName=storage.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=storage.api.onmetal.de package storage import ( diff --git a/apis/storage/v1alpha1/register.go b/apis/storage/v1alpha1/register.go index c7f698452..0d799ed07 100644 --- a/apis/storage/v1alpha1/register.go +++ b/apis/storage/v1alpha1/register.go @@ -15,8 +15,8 @@ */ // Package v1alpha1 contains API Schema definitions for the storage v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=storage.api.onmetal.de +// +kubebuilder:object:generate=true +// +groupName=storage.api.onmetal.de package v1alpha1 import ( diff --git a/controllers/ipam/prefix_controller.go b/controllers/ipam/prefix_controller.go index 60226126b..bf0cffd6d 100644 --- a/controllers/ipam/prefix_controller.go +++ b/controllers/ipam/prefix_controller.go @@ -348,11 +348,11 @@ func (r *PrefixReconciler) allocateSubPrefix(ctx context.Context, log logr.Logge // adjustedAllocationPhase calculates an adjusted phase of a PrefixAllocation. // For the adjusted phase, it is considered -// * If the allocation is in a terminal phase, that state is returned. -// * If the allocation is not scheduled, that state is returned. -// * If the allocation is scheduled but no lastTransitionTime has been recorded, that state is returned -// * If the allocation is in a non-terminal state, and it has been scheduled, once a configurable timeout has passed, -// it is considered to be failed. +// - If the allocation is in a terminal phase, that state is returned. +// - If the allocation is not scheduled, that state is returned. +// - If the allocation is scheduled but no lastTransitionTime has been recorded, that state is returned +// - If the allocation is in a non-terminal state, and it has been scheduled, once a configurable timeout has passed, +// it is considered to be failed. func (r *PrefixReconciler) adjustedAllocationPhase(allocation *ipamv1alpha1.PrefixAllocation) ipamv1alpha1.PrefixAllocationPhase { allocationPhase := allocation.Status.Phase if allocationPhase.IsTerminal() || allocation.Spec.PrefixRef == nil { diff --git a/docs/development/setup.md b/docs/development/setup.md index d6f9c5e5c..d22e676fc 100644 --- a/docs/development/setup.md +++ b/docs/development/setup.md @@ -2,7 +2,7 @@ ## Requirements -* `go` >= 1.17 +* `go` >= 1.19 * `git`, `make` and `kubectl` * [Kustomize](https://kustomize.io/) * Access to a Kubernetes cluster ([Minikube](https://minikube.sigs.k8s.io/docs/), [kind](https://kind.sigs.k8s.io/) or a diff --git a/envtestutils/apiservice.go b/envtestutils/apiservice.go index a4810bd5a..f7a91dbd5 100644 --- a/envtestutils/apiservice.go +++ b/envtestutils/apiservice.go @@ -18,7 +18,6 @@ import ( "bufio" "bytes" "io" - "io/ioutil" "os" "path/filepath" @@ -79,8 +78,20 @@ func renderAPIServices(options *APIServiceInstallOptions) ([]*apiregistrationv1. if !info.IsDir() { filePath, files = filepath.Dir(path), []os.FileInfo{info} - } else if files, err = ioutil.ReadDir(path); err != nil { - return nil, err + } else { + entries, err := os.ReadDir(path) + if err != nil { + return nil, err + } + + for _, entry := range entries { + file, err := entry.Info() + if err != nil { + return nil, err + } + + files = append(files, file) + } } log.V(1).Info("reading APIServices from path", "path", path) diff --git a/envtestutils/envtestutils.go b/envtestutils/envtestutils.go index 372ea3c79..9bb6da378 100644 --- a/envtestutils/envtestutils.go +++ b/envtestutils/envtestutils.go @@ -17,7 +17,6 @@ package envtestutils import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -106,7 +105,7 @@ func (o *APIServiceInstallOptions) setupCA() error { return fmt.Errorf("unable to set up api service serving certs: %v", err) } - localServingCertsDir, err := ioutil.TempDir("", "envtest-apiservice-certs-") + localServingCertsDir, err := os.MkdirTemp("", "envtest-apiservice-certs-") o.LocalServingCertDir = localServingCertsDir if err != nil { return fmt.Errorf("unable to create directory for apiservice serving certs: %v", err) @@ -117,13 +116,13 @@ func (o *APIServiceInstallOptions) setupCA() error { return fmt.Errorf("unable to marshal api service serving certs: %v", err) } - if err := ioutil.WriteFile(o.caCertPath(), apiServiceCA.CA.CertBytes(), 0640); err != nil { + if err := os.WriteFile(o.caCertPath(), apiServiceCA.CA.CertBytes(), 0640); err != nil { return fmt.Errorf("unable to write api service ca to disk: %w", err) } - if err := ioutil.WriteFile(o.tlsCertPath(), certData, 0640); err != nil { + if err := os.WriteFile(o.tlsCertPath(), certData, 0640); err != nil { return fmt.Errorf("unable to write api service serving cert to disk: %w", err) } - if err := ioutil.WriteFile(o.tlsKeyPath(), keyData, 0640); err != nil { + if err := os.WriteFile(o.tlsKeyPath(), keyData, 0640); err != nil { return fmt.Errorf("unable to write api service serving key to disk: %w", err) } @@ -232,7 +231,7 @@ func (o *APIServiceInstallOptions) SetupClientCA() error { return fmt.Errorf("unable to set up apiserver client serving certs: %v", err) } - clientCertDir, err := ioutil.TempDir("", "envtest-apiserver-client-certs-") + clientCertDir, err := os.MkdirTemp("", "envtest-apiserver-client-certs-") o.ClientCertDir = clientCertDir if err != nil { return fmt.Errorf("unable to create directory for apiserver client certs: %v", err) @@ -243,13 +242,13 @@ func (o *APIServiceInstallOptions) SetupClientCA() error { return fmt.Errorf("unable to marshal apiserver client certs: %v", err) } - if err := ioutil.WriteFile(o.clientCACertPath(), clientCA.CA.CertBytes(), 0640); err != nil { + if err := os.WriteFile(o.clientCACertPath(), clientCA.CA.CertBytes(), 0640); err != nil { return fmt.Errorf("unable to write apiserver client ca to disk: %w", err) } - if err := ioutil.WriteFile(o.clientCertPath(), certData, 0640); err != nil { + if err := os.WriteFile(o.clientCertPath(), certData, 0640); err != nil { return fmt.Errorf("unable to write apiserver client cert to disk: %w", err) } - if err := ioutil.WriteFile(o.clientKeyPath(), keyData, 0640); err != nil { + if err := os.WriteFile(o.clientKeyPath(), keyData, 0640); err != nil { return fmt.Errorf("unable to write apiserver client key to disk: %w", err) } diff --git a/generated/clientset/internalversion/fake/register.go b/generated/clientset/internalversion/fake/register.go index 8e7347fb7..29bb48a66 100644 --- a/generated/clientset/internalversion/fake/register.go +++ b/generated/clientset/internalversion/fake/register.go @@ -42,14 +42,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/generated/clientset/versioned/fake/register.go b/generated/clientset/versioned/fake/register.go index d97bdf0bc..4101c7d10 100644 --- a/generated/clientset/versioned/fake/register.go +++ b/generated/clientset/versioned/fake/register.go @@ -42,14 +42,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/generated/clientset/versioned/scheme/register.go b/generated/clientset/versioned/scheme/register.go index 7299e58e5..5aa4e8436 100644 --- a/generated/clientset/versioned/scheme/register.go +++ b/generated/clientset/versioned/scheme/register.go @@ -42,14 +42,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{ // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/go.mod b/go.mod index b06bb749e..fcbbe38b5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/onmetal/onmetal-api -go 1.18 +go 1.19 require ( github.com/ahmetb/gen-crd-api-reference-docs v0.3.0 diff --git a/registry/compute/machineclass/strategy.go b/registry/compute/machineclass/strategy.go index f366eb108..c7df35796 100644 --- a/registry/compute/machineclass/strategy.go +++ b/registry/compute/machineclass/strategy.go @@ -71,7 +71,7 @@ func (machineClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runti newMachineClass := obj.(*compute.MachineClass) oldMachineClass := old.(*compute.MachineClass) - if !equality.Semantic.DeepEqual(&newMachineClass.Capabilities, oldMachineClass.Capabilities) { + if !equality.Semantic.DeepEqual(newMachineClass.Capabilities, oldMachineClass.Capabilities) { newMachineClass.Generation = oldMachineClass.Generation + 1 } } diff --git a/registry/compute/machinepool/strategy.go b/registry/compute/machinepool/strategy.go index 5402be36b..336f96e48 100644 --- a/registry/compute/machinepool/strategy.go +++ b/registry/compute/machinepool/strategy.go @@ -82,7 +82,7 @@ func (machinePoolStrategy) PrepareForUpdate(ctx context.Context, obj, old runtim oldMachinePool := old.(*compute.MachinePool) newMachinePool.Status = oldMachinePool.Status - if !equality.Semantic.DeepEqual(&newMachinePool.Spec, oldMachinePool.Spec) { + if !equality.Semantic.DeepEqual(newMachinePool.Spec, oldMachinePool.Spec) { newMachinePool.Generation = oldMachinePool.Generation + 1 } } diff --git a/registry/storage/volumepool/strategy.go b/registry/storage/volumepool/strategy.go index a3508b59b..048450bbb 100644 --- a/registry/storage/volumepool/strategy.go +++ b/registry/storage/volumepool/strategy.go @@ -82,7 +82,7 @@ func (volumePoolStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime oldVolumePool := old.(*storage.VolumePool) newVolumePool.Status = oldVolumePool.Status - if !equality.Semantic.DeepEqual(&newVolumePool.Spec, oldVolumePool.Spec) { + if !equality.Semantic.DeepEqual(newVolumePool.Spec, oldVolumePool.Spec) { newVolumePool.Generation = oldVolumePool.Generation + 1 } }