Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Apr 16, 2024
1 parent fa7dfa5 commit 46b8ccb
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 84 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/provider_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

apimachineryconversion "k8s.io/apimachinery/pkg/conversion"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
ctrlconfigv1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
Expand Down Expand Up @@ -525,5 +525,5 @@ func fromImageMeta(im *ImageMeta) *string {
result = result + ":" + im.Tag
}

return pointer.String(result)
return ptr.To(result)
}
6 changes: 4 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/cluster-api-operator/internal/webhook"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
Expand Down Expand Up @@ -131,7 +131,9 @@ func main() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

ctrl.SetLogger(klogr.New())
loggerConfig := textlogger.NewConfig([]textlogger.ConfigOption{}...)
ctrl.SetLogger(textlogger.NewLogger(loggerConfig))

restConfig := ctrl.GetConfigOrDie()

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)
Expand Down
5 changes: 3 additions & 2 deletions cmd/plugin/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2/klogr"
"k8s.io/klog/v2/textlogger"

kerrors "k8s.io/apimachinery/pkg/util/errors"

Expand Down Expand Up @@ -142,7 +142,8 @@ func init() {
func runDelete() error {
ctx := context.Background()

ctrl.SetLogger(klogr.New())
loggerConfig := textlogger.NewConfig([]textlogger.ConfigOption{}...)
ctrl.SetLogger(textlogger.NewLogger(loggerConfig))

hasProviderNames := deleteOpts.coreProvider ||
(len(deleteOpts.bootstrapProviders) > 0) ||
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestInitProviders(t *testing.T) {

for _, genericProvider := range tt.wantedProviders {
g.Eventually(func(g Gomega) {
copy := genericProvider.DeepCopyObject().(generic.Provider)
copy := genericProvider.DeepCopyObject().(generic.Provider) //nolint
g.Expect(env.Get(ctx, ctrlclient.ObjectKeyFromObject(genericProvider), copy)).To(Succeed())
g.Expect(copy.GetSpec().Version).To(Equal(genericProvider.GetSpec().Version))
}, waitShort).Should(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/cmd/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"

// We need to initalize all registered providers
// We need to initialize all registered providers.
_ "sigs.k8s.io/cluster-api-operator/internal/controller/providers"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"sigs.k8s.io/cluster-api-operator/cmd/plugin/cmd"

// We need to initalize all registered providers
// We need to initialize all registered providers.
_ "sigs.k8s.io/cluster-api-operator/internal/controller/providers"
)

Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v52 v52.0.0
github.com/google/gofuzz v1.2.0
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.32.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -52,6 +53,7 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -60,6 +62,7 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-github/v53 v53.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down Expand Up @@ -111,6 +114,7 @@ require (
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/generic/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Group[P Provider] interface {
GetClusterctlProvider() *clusterctlv1.Provider
}

// NewGroup is a function that creates a new group
// NewGroup is a function that creates a new group.
type NewGroup[P Provider] func(P, ProviderList, GroupBuilder[P]) Group[P]

type ProviderReconciler[P Provider] interface {
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/phases/component_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/client-go/kubernetes/scheme"
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
"sigs.k8s.io/cluster-api/util"
)
Expand Down Expand Up @@ -131,7 +131,7 @@ func customizeDeploymentSpec(pSpec operatorv1.ProviderSpec, d *appsv1.Deployment
dSpec := pSpec.Deployment

if dSpec.Replicas != nil {
d.Spec.Replicas = pointer.Int32(int32(*dSpec.Replicas))
d.Spec.Replicas = ptr.To(int32(*dSpec.Replicas))
}

if dSpec.Affinity != nil {
Expand Down
22 changes: 11 additions & 11 deletions internal/controller/phases/component_customizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes/scheme"
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
)
Expand Down Expand Up @@ -112,11 +112,11 @@ func TestCustomizeDeployment(t *testing.T) {
{
name: "only replicas modified",
inputDeploymentSpec: &operatorv1.DeploymentSpec{
Replicas: pointer.Int(3),
Replicas: ptr.To(3),
},
expectedDeploymentSpec: func(inputDS *appsv1.DeploymentSpec) (*appsv1.DeploymentSpec, bool) {
expectedDS := &appsv1.DeploymentSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
}

return expectedDS, reflect.DeepEqual(inputDS.Replicas, expectedDS.Replicas)
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestCustomizeDeployment(t *testing.T) {
Containers: []operatorv1.ContainerSpec{
{
Name: "manager",
ImageURL: pointer.String("quay.io/dev/mydns:v3.4.2"),
ImageURL: ptr.To("quay.io/dev/mydns:v3.4.2"),
Env: []corev1.EnvVar{
{
Name: "test1",
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestCustomizeDeployment(t *testing.T) {
{
name: "all deployment options",
inputDeploymentSpec: &operatorv1.DeploymentSpec{
Replicas: pointer.Int(3),
Replicas: ptr.To(3),
NodeSelector: map[string]string{"a": "b"},
Tolerations: []corev1.Toleration{
{
Expand All @@ -351,7 +351,7 @@ func TestCustomizeDeployment(t *testing.T) {
Containers: []operatorv1.ContainerSpec{
{
Name: "manager",
ImageURL: pointer.String("quay.io/dev/mydns:v3.4.2"),
ImageURL: ptr.To("quay.io/dev/mydns:v3.4.2"),
Env: []corev1.EnvVar{
{
Name: "test1",
Expand All @@ -375,7 +375,7 @@ func TestCustomizeDeployment(t *testing.T) {
},
expectedDeploymentSpec: func(inputDS *appsv1.DeploymentSpec) (*appsv1.DeploymentSpec, bool) {
expectedDS := &appsv1.DeploymentSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
NodeSelector: map[string]string{"a": "b"},
Expand Down Expand Up @@ -480,11 +480,11 @@ func TestCustomizeDeployment(t *testing.T) {
LivenessEndpointName: "mostly",
},
Webhook: operatorv1.ControllerWebhook{
Port: pointer.Int(3579),
Port: ptr.To(3579),
CertDir: "/tmp/certs",
},
LeaderElection: &configv1alpha1.LeaderElectionConfiguration{
LeaderElect: pointer.Bool(true),
LeaderElect: ptr.To(true),
ResourceName: "foo",
ResourceNamespace: "here",
LeaseDuration: metav1.Duration{Duration: sevenHours},
Expand Down Expand Up @@ -602,7 +602,7 @@ func TestCustomizeMultipleDeployment(t *testing.T) {
Namespace: metav1.NamespaceSystem,
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
},
}

Expand All @@ -627,7 +627,7 @@ func TestCustomizeMultipleDeployment(t *testing.T) {
Spec: operatorv1.CoreProviderSpec{
ProviderSpec: operatorv1.ProviderSpec{
Deployment: &operatorv1.DeploymentSpec{
Replicas: pointer.Int(10),
Replicas: ptr.To(10),
},
},
},
Expand Down
7 changes: 4 additions & 3 deletions internal/controller/phases/preflight_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func PreflightChecks[P generic.Provider](ctx context.Context, phase generic.Grou
return ctrl.Result{}, fmt.Errorf("failed to generate a list of predefined providers: %w", err)
}

if !isPredefinedProvider && spec.FetchConfig == nil {
switch {
case !isPredefinedProvider && spec.FetchConfig == nil:
conditions.Set(phase.GetProvider(), conditions.FalseCondition(
operatorv1.PreflightCheckCondition,
operatorv1.FetchConfigValidationErrorReason,
Expand All @@ -72,7 +73,7 @@ func PreflightChecks[P generic.Provider](ctx context.Context, phase generic.Grou
))

return ctrl.Result{}, fmt.Errorf("either selector or URL must be provided for a not predefined provider %s", phase.GetProvider().GetName())
} else if spec.FetchConfig != nil && (spec.FetchConfig.Selector == nil && spec.FetchConfig.URL == "") {
case spec.FetchConfig != nil && (spec.FetchConfig.Selector == nil && spec.FetchConfig.URL == ""):
conditions.Set(phase.GetProvider(), conditions.FalseCondition(
operatorv1.PreflightCheckCondition,
operatorv1.FetchConfigValidationErrorReason,
Expand All @@ -81,7 +82,7 @@ func PreflightChecks[P generic.Provider](ctx context.Context, phase generic.Grou
))

return ctrl.Result{}, fmt.Errorf("either selector or URL must be provided for provider %s", phase.GetProvider().GetName())
} else if spec.FetchConfig != nil && spec.FetchConfig.Selector != nil && spec.FetchConfig.URL != "" {
case spec.FetchConfig != nil && spec.FetchConfig.Selector != nil && spec.FetchConfig.URL != "":
// If FetchConfiguration is not nil, exactly one of `URL` or `Selector` must be specified.
conditions.Set(phase.GetProvider(), conditions.FalseCondition(
operatorv1.PreflightCheckCondition,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/preflight_checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func TestInfrastructurePreflightChecks(t *testing.T) {
}

for _, c := range tc.otherProviders {
gs.Expect(fakeclient.Create(ctx, c.DeepCopyObject().(client.Object))).To(Succeed())
gs.Expect(fakeclient.Create(ctx, c.DeepCopyObject().(client.Object))).To(Succeed()) //nolint:forcetypeassert
}

rec := NewProviderControllerWrapper(
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/provider_controller_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const (

func (r *ProviderControllerWrapper[P, R]) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
For(reflect.New(reflect.TypeOf(*new(P)).Elem()).Interface().(P)).
For(reflect.New(reflect.TypeOf(*new(P)).Elem()).Interface().(P)). //nolint:forcetypeassert
WithOptions(options).
Complete(reconcile.AsReconciler(mgr.GetClient(), r))
}
Expand Down
1 change: 1 addition & 0 deletions internal/controller/provider_controller_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ releaseSeries:
}

conditions.MarkTrue(core, clusterv1.ReadyCondition)

return env.Status().Update(ctx, core)
}).Should(Succeed())

Expand Down
15 changes: 8 additions & 7 deletions internal/controller/providers/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ func NewAddonProviderReconciler(conn generic.Connector) generic.ProviderReconcil
}
}

// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider
// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider.
func (r *AddonProviderReconciler) ClusterctlProviderType() clusterctlv1.ProviderType {
return clusterctlv1.AddonProviderType
}

// ClusterctlProvider returns Provider stucture of the underlying clusterctl provider
// ClusterctlProvider returns Provider structure of the underlying clusterctl provider.
func (r *AddonProviderReconciler) ClusterctlProvider(provider *operatorv1.AddonProvider) *clusterctlv1.Provider {
clusterctlProvider := &clusterctlv1.Provider{ObjectMeta: metav1.ObjectMeta{
Name: "addon-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
clusterctlProvider := &clusterctlv1.Provider{
ObjectMeta: metav1.ObjectMeta{
Name: "addon-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
Type: string(r.ClusterctlProviderType()),
ProviderName: provider.GetName(),
Version: *util.Or(provider.GetStatus().InstalledVersion, ptr.To("")),
Expand All @@ -55,7 +56,7 @@ func (r *AddonProviderReconciler) ClusterctlProvider(provider *operatorv1.AddonP
return clusterctlProvider
}

// ProviderList returns empty typed list for provider
// GetProviderList returns empty typed list for provider.
func (r *AddonProviderReconciler) GetProviderList() generic.ProviderList {
return &operatorv1.AddonProviderList{}
}
15 changes: 8 additions & 7 deletions internal/controller/providers/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ func NewBootstrapProviderReconciler(conn generic.Connector) generic.ProviderReco
}
}

// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider
// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider.
func (r *BootstrapProviderReconciler) ClusterctlProviderType() clusterctlv1.ProviderType {
return clusterctlv1.BootstrapProviderType
}

// ClusterctlProvider returns Provider stucture of the underlying clusterctl provider
// ClusterctlProvider returns Provider structure of the underlying clusterctl provider.
func (r *BootstrapProviderReconciler) ClusterctlProvider(provider *operatorv1.BootstrapProvider) *clusterctlv1.Provider {
clusterctlProvider := &clusterctlv1.Provider{ObjectMeta: metav1.ObjectMeta{
Name: "bootstrap-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
clusterctlProvider := &clusterctlv1.Provider{
ObjectMeta: metav1.ObjectMeta{
Name: "bootstrap-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
Type: string(r.ClusterctlProviderType()),
ProviderName: provider.GetName(),
Version: *util.Or(provider.GetStatus().InstalledVersion, ptr.To("")),
Expand All @@ -55,7 +56,7 @@ func (r *BootstrapProviderReconciler) ClusterctlProvider(provider *operatorv1.Bo
return clusterctlProvider
}

// ProviderList returns empty typed list for provider
// GetProviderList returns empty typed list for provider.
func (r *BootstrapProviderReconciler) GetProviderList() generic.ProviderList {
return &operatorv1.BootstrapProviderList{}
}
15 changes: 8 additions & 7 deletions internal/controller/providers/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ func NewControlPlaneProviderReconciler(conn generic.Connector) generic.ProviderR
}
}

// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider
// ClusterctlProviderType returns ProviderType for the underlying clusterctl provider.
func (r *ControlPlaneProviderReconciler) ClusterctlProviderType() clusterctlv1.ProviderType {
return clusterctlv1.ControlPlaneProviderType
}

// ClusterctlProvider returns Provider stucture of the underlying clusterctl provider
// ClusterctlProvider returns Provider structure of the underlying clusterctl provider.
func (r *ControlPlaneProviderReconciler) ClusterctlProvider(provider *operatorv1.ControlPlaneProvider) *clusterctlv1.Provider {
clusterctlProvider := &clusterctlv1.Provider{ObjectMeta: metav1.ObjectMeta{
Name: "control-plane-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
clusterctlProvider := &clusterctlv1.Provider{
ObjectMeta: metav1.ObjectMeta{
Name: "control-plane-" + provider.GetName(),
Namespace: provider.GetNamespace(),
},
Type: string(r.ClusterctlProviderType()),
ProviderName: provider.GetName(),
Version: *util.Or(provider.GetStatus().InstalledVersion, ptr.To("")),
Expand All @@ -54,7 +55,7 @@ func (r *ControlPlaneProviderReconciler) ClusterctlProvider(provider *operatorv1
return clusterctlProvider
}

// ProviderList returns empty typed list for provider
// GetProviderList returns empty typed list for provider.
func (r *ControlPlaneProviderReconciler) GetProviderList() generic.ProviderList {
return &operatorv1.ControlPlaneProviderList{}
}
Loading

0 comments on commit 46b8ccb

Please sign in to comment.