Skip to content

Commit

Permalink
Update files with lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil Grigorev committed Oct 17, 2023
1 parent e0fbc7b commit 2388fb7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion bootstrap/api/v1alpha1/rke2config_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/api/v1alpha1/rke2configtemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/registration/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions pkg/rke2/registries_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/rke2/workload_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ 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"
"sigs.k8s.io/cluster-api/util/annotations"
"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"
)
Expand Down
6 changes: 1 addition & 5 deletions pkg/secret/certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions test/helpers/envtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
}

Expand All @@ -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 {
Expand All @@ -179,12 +182,14 @@ 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")
}

func envOr(envKey, defaultValue string) string {
if value, ok := os.LookupEnv(envKey); ok {
return value
}

return defaultValue
}

0 comments on commit 2388fb7

Please sign in to comment.