diff --git a/bootstrap/api/v1alpha1/rke2config_webhook.go b/bootstrap/api/v1alpha1/rke2config_webhook.go index 56e4ab7c..0f703c41 100644 --- a/bootstrap/api/v1alpha1/rke2config_webhook.go +++ b/bootstrap/api/v1alpha1/rke2config_webhook.go @@ -98,7 +98,7 @@ func (r *RKE2Config) ValidateDelete() (admission.Warnings, error) { } // ValidateRKE2ConfigSpec validates the RKE2ConfigSpec. -func ValidateRKE2ConfigSpec(name string, spec *RKE2ConfigSpec) field.ErrorList { +func ValidateRKE2ConfigSpec(_ string, spec *RKE2ConfigSpec) field.ErrorList { allErrs := spec.validate(field.NewPath("spec")) if len(allErrs) == 0 { diff --git a/bootstrap/api/v1alpha1/rke2configtemplate_webhook.go b/bootstrap/api/v1alpha1/rke2configtemplate_webhook.go index 1143baf6..1532ad91 100644 --- a/bootstrap/api/v1alpha1/rke2configtemplate_webhook.go +++ b/bootstrap/api/v1alpha1/rke2configtemplate_webhook.go @@ -55,7 +55,7 @@ func (r *RKE2ConfigTemplate) ValidateCreate() (admission.Warnings, error) { } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -func (r *RKE2ConfigTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *RKE2ConfigTemplate) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { RKE2configtemplatelog.Info("validate update", "name", r.Name) return nil, nil diff --git a/controlplane/api/v1alpha1/rke2controlplanetemplate_webhook.go b/controlplane/api/v1alpha1/rke2controlplanetemplate_webhook.go index 1ee5a734..17b26dd1 100644 --- a/controlplane/api/v1alpha1/rke2controlplanetemplate_webhook.go +++ b/controlplane/api/v1alpha1/rke2controlplanetemplate_webhook.go @@ -55,7 +55,7 @@ func (r *RKE2ControlPlaneTemplate) ValidateCreate() (admission.Warnings, error) } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -func (r *RKE2ControlPlaneTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { +func (r *RKE2ControlPlaneTemplate) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { rke2controlplanetemplatelog.Info("validate update", "name", r.Name) return nil, nil diff --git a/pkg/registration/registration.go b/pkg/registration/registration.go index 39a6f0b6..615b6bdd 100644 --- a/pkg/registration/registration.go +++ b/pkg/registration/registration.go @@ -61,7 +61,7 @@ func registrationMethodWithFilter(filter addressFilter) GetRegistrationAddresses } } -func registrationMethodAddress(rcp *controlplanev1.RKE2ControlPlane, availableMachines collections.Machines) ([]string, error) { +func registrationMethodAddress(rcp *controlplanev1.RKE2ControlPlane, _ collections.Machines) ([]string, error) { validIPAddresses := []string{} validIPAddresses = append(validIPAddresses, rcp.Spec.RegistrationAddress) diff --git a/pkg/rke2/registries_types.go b/pkg/rke2/registries_types.go index e6ae8a8d..ad2efdc7 100644 --- a/pkg/rke2/registries_types.go +++ b/pkg/rke2/registries_types.go @@ -30,52 +30,52 @@ type Mirror struct { // one by one until a working one is found. The endpoint must be a valid url // with host specified. // The scheme, host and path from the endpoint URL will be used. - Endpoint []string `toml:"endpoint" yaml:"endpoint" json:"endpoint"` + Endpoint []string `json:"endpoint" toml:"endpoint" yaml:"endpoint"` // Rewrites are repository rewrite rules for a namespace. When fetching image resources // from an endpoint and a key matches the repository via regular expression matching // it will be replaced with the corresponding value from the map in the resource request. - Rewrite map[string]string `toml:"rewrite" yaml:"rewrite,omitempty" json:"rewrite,omitempty"` + Rewrite map[string]string `json:"rewrite,omitempty" toml:"rewrite" yaml:"rewrite,omitempty"` } // AuthConfig contains the config related to authentication to a specific registry. type AuthConfig struct { // Username is the username to login the registry. - Username string `toml:"username" yaml:"username,omitempty" json:"username,omitempty"` + Username string `json:"username,omitempty" toml:"username" yaml:"username,omitempty"` // Password is the password to login the registry. - Password string `toml:"password" yaml:"password,omitempty" json:"password,omitempty"` + Password string `json:"password,omitempty" toml:"password" yaml:"password,omitempty"` // Auth is a base64 encoded string from the concatenation of the username, // a colon, and the password. - Auth string `toml:"auth" yaml:"auth,omitempty" json:"auth,omitempty"` + Auth string `json:"auth,omitempty" toml:"auth" yaml:"auth,omitempty"` // IdentityToken is used to authenticate the user and get // an access token for the registry. - IdentityToken string `toml:"identitytoken" yaml:"identity_token,omitempty" json:"identity_token,omitempty"` + IdentityToken string `json:"identity_token,omitempty" toml:"identitytoken" yaml:"identity_token,omitempty"` } // TLSConfig contains the CA/Cert/Key used for a registry. type TLSConfig struct { - CAFile string `toml:"ca_file" yaml:"ca_file" json:"ca_file"` - CertFile string `toml:"cert_file" yaml:"cert_file" json:"cert_file"` - KeyFile string `toml:"key_file" yaml:"key_file" json:"key_file"` - InsecureSkipVerify bool `toml:"insecure_skip_verify" yaml:"insecure_skip_verify" json:"insecure_skip_verify"` + CAFile string `json:"ca_file" toml:"ca_file" yaml:"ca_file"` + CertFile string `json:"cert_file" toml:"cert_file" yaml:"cert_file"` + KeyFile string `json:"key_file" toml:"key_file" yaml:"key_file"` + InsecureSkipVerify bool `json:"insecure_skip_verify" toml:"insecure_skip_verify" yaml:"insecure_skip_verify"` } // Registry is registry settings including mirrors, TLS, and credentials. type Registry struct { // Mirrors are namespace to mirror mapping for all namespaces. - Mirrors map[string]Mirror `toml:"mirrors" yaml:"mirrors" json:"mirrors"` + Mirrors map[string]Mirror `json:"mirrors" toml:"mirrors" yaml:"mirrors"` // Configs are configs for each registry. // The key is the FDQN or IP of the registry. - Configs map[string]RegistryConfig `toml:"configs" yaml:"configs" json:"configs"` + Configs map[string]RegistryConfig `json:"configs" toml:"configs" yaml:"configs"` } // RegistryConfig contains configuration used to communicate with the registry. type RegistryConfig struct { // Auth contains information to authenticate to the registry. - Auth *AuthConfig `toml:"auth" yaml:"auth,omitempty" json:"auth,omitempty"` + Auth *AuthConfig `json:"auth,omitempty" toml:"auth" yaml:"auth,omitempty"` // TLS is a pair of CA/Cert/Key which then are used when creating the transport // that communicates with the registry. - TLS *TLSConfig `toml:"tls" yaml:"tls,omitempty" json:"tls,omitempty"` + TLS *TLSConfig `json:"tls,omitempty" toml:"tls" yaml:"tls,omitempty"` } // RegistryScope is a wrapper around the Registry struct to provide diff --git a/pkg/rke2/workload_cluster.go b/pkg/rke2/workload_cluster.go index 014b6f13..5e939770 100644 --- a/pkg/rke2/workload_cluster.go +++ b/pkg/rke2/workload_cluster.go @@ -22,10 +22,10 @@ import ( "strings" "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/sets" + "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util" @@ -33,7 +33,6 @@ import ( "sigs.k8s.io/cluster-api/util/collections" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" - "sigs.k8s.io/controller-runtime/pkg/client" controlplanev1 "github.com/rancher-sandbox/cluster-api-provider-rke2/controlplane/api/v1alpha1" ) diff --git a/pkg/secret/certificates.go b/pkg/secret/certificates.go index 36568f99..036887c7 100644 --- a/pkg/secret/certificates.go +++ b/pkg/secret/certificates.go @@ -227,11 +227,7 @@ func (c Certificates) LookupOrGenerate( } // Save any certificates that have been generated - if err := c.SaveGenerated(ctx, ctrlclient, clusterName, owner); err != nil { - return err - } - - return nil + return c.SaveGenerated(ctx, ctrlclient, clusterName, owner) } // AsSecret converts a single certificate into a Kubernetes secret. diff --git a/test/helpers/envtest.go b/test/helpers/envtest.go index 1c703028..908b3dc4 100644 --- a/test/helpers/envtest.go +++ b/test/helpers/envtest.go @@ -54,7 +54,7 @@ func init() { root = path.Join(path.Dir(filename), "..", "..") } -// TestEnvironmentConfiguration is a wrapper configuration for envtest +// TestEnvironmentConfiguration is a wrapper configuration for envtest. type TestEnvironmentConfiguration struct { env *envtest.Environment } @@ -71,6 +71,7 @@ type TestEnvironment struct { // Cleanup deletes all the given objects. func (t *TestEnvironment) Cleanup(ctx context.Context, objs ...client.Object) error { errs := []error{} + for _, o := range objs { err := t.Client.Delete(ctx, o) if apierrors.IsNotFound(err) { @@ -134,7 +135,6 @@ func (t *TestEnvironmentConfiguration) Build() (*TestEnvironment, error) { } mgr, err := ctrl.NewManager(t.env.Config, options) - if err != nil { klog.Fatalf("Failed to start testenv manager: %v", err) } @@ -151,12 +151,14 @@ func (t *TestEnvironmentConfiguration) Build() (*TestEnvironment, error) { func (t *TestEnvironment) StartManager(ctx context.Context) error { ctx, cancel := context.WithCancel(ctx) t.cancel = cancel + return t.Manager.Start(ctx) } // Stop stops the test environment. func (t *TestEnvironment) Stop() error { t.cancel() + return t.env.Stop() } @@ -167,6 +169,7 @@ func getFilePathToCAPICRDs(root string) string { } var clusterAPIVersion string + for _, line := range strings.Split(string(modBits), "\n") { matches := clusterAPIVersionRegex.FindStringSubmatch(line) if len(matches) == 3 { @@ -179,6 +182,7 @@ func getFilePathToCAPICRDs(root string) string { } gopath := envOr("GOPATH", build.Default.GOPATH) + return filepath.Join(gopath, "pkg", "mod", "sigs.k8s.io", fmt.Sprintf("cluster-api@v%s", clusterAPIVersion), "config", "crd", "bases") } @@ -186,5 +190,6 @@ func envOr(envKey, defaultValue string) string { if value, ok := os.LookupEnv(envKey); ok { return value } + return defaultValue }