Skip to content

Commit

Permalink
🌱 Fix linting and tests
Browse files Browse the repository at this point in the history
Fix linting in new clusteraddon-related files that we changed in the
feature branch.

Fixing unit tests.

Signed-off-by: janiskemper <[email protected]>
  • Loading branch information
janiskemper committed Jun 26, 2024
1 parent c6cfdfd commit f44988e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 67 deletions.
104 changes: 52 additions & 52 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ patchesStrategicMerge:
- webhookcainjection_patch.yaml
- manager_pull_policy.yaml
vars:
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: HOOK_SERVER_CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: hook-server-server-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
- name: HOOK_SERVER_CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: hook-server-server-cert # this name should match the one in certificate.yaml
- name: SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: webhook-service
fieldref:
fieldpath: metadata.namespace
- name: HOOK_SERVER_SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: hook-server-svc
fieldref:
fieldpath: metadata.namespace
- name: SERVICE_NAME
objref:
kind: Service
version: v1
name: webhook-service
- name: HOOK_SERVER_SERVICE_NAME
objref:
kind: Service
version: v1
name: hook-server-svc
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: HOOK_SERVER_CERTIFICATE_NAMESPACE # namespace of the certificate CR
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: hook-server-server-cert # this name should match the one in certificate.yaml
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert # this name should match the one in certificate.yaml
- name: HOOK_SERVER_CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: hook-server-server-cert # this name should match the one in certificate.yaml
- name: SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: webhook-service
fieldref:
fieldpath: metadata.namespace
- name: HOOK_SERVER_SERVICE_NAMESPACE # namespace of the service
objref:
kind: Service
version: v1
name: hook-server-svc
fieldref:
fieldpath: metadata.namespace
- name: SERVICE_NAME
objref:
kind: Service
version: v1
name: webhook-service
- name: HOOK_SERVER_SERVICE_NAME
objref:
kind: Service
version: v1
name: hook-server-svc
27 changes: 16 additions & 11 deletions internal/controller/clusteraddon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ import (

const clusterAddonNamespace = "kube-system"

const (
beforeClusterUpgradeHook = "BeforeClusterUpgrade"
afterControlPlaneInitialized = "AfterControlPlaneInitialized"
)

// RestConfigSettings contains Kubernetes rest config settings.
type RestConfigSettings struct {
QPS float32
Expand Down Expand Up @@ -344,8 +349,8 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class && oldRelease != nil && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
if clusterAddon.Spec.Version != releaseAsset.Meta.Versions.Components.ClusterAddon {
if clusterAddon.Status.Ready || len(clusterAddon.Status.Stages) == 0 {
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, len(clusterAddonConfig.AddonStages["BeforeClusterUpgrade"]))
for i, stage := range clusterAddonConfig.AddonStages["BeforeClusterUpgrade"] {
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, len(clusterAddonConfig.AddonStages[beforeClusterUpgradeHook]))
for i, stage := range clusterAddonConfig.AddonStages[beforeClusterUpgradeHook] {
clusterAddon.Status.Stages[i].Name = stage.Name
clusterAddon.Status.Stages[i].Action = stage.Action
clusterAddon.Status.Stages[i].Phase = csov1alpha1.StagePhasePending
Expand All @@ -369,9 +374,9 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
// In case the Kubernetes version stayed the same during an upgrade, the hook server does not trigger and
// we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
if oldRelease != nil && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
clusterAddon.Spec.Hook = "BeforeClusterUpgrade"
clusterAddon.Spec.Hook = beforeClusterUpgradeHook

for _, stage := range clusterAddonConfig.AddonStages["BeforeClusterUpgrade"] {
for _, stage := range clusterAddonConfig.AddonStages[beforeClusterUpgradeHook] {
shouldRequeue, err := r.executeStage(ctx, stage, in)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to execute stage: %w", err)
Expand Down Expand Up @@ -445,8 +450,8 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
}
}

if clusterAddon.Spec.Hook == "AfterControlPlaneInitialized" || clusterAddon.Spec.Hook == "BeforeClusterUpgrade" {
if clusterAddon.Spec.Hook == "BeforeClusterUpgrade" {
if clusterAddon.Spec.Hook == afterControlPlaneInitialized || clusterAddon.Spec.Hook == beforeClusterUpgradeHook {
if clusterAddon.Spec.Hook == beforeClusterUpgradeHook {
// create the list of old release objects
oldClusterStackObjectList, err := r.getOldReleaseObjects(ctx, in, clusterAddonConfig, oldRelease)
if err != nil {
Expand Down Expand Up @@ -570,9 +575,9 @@ func (r *ClusterAddonReconciler) getOldReleaseObjects(ctx context.Context, in *t
)

if in.clusterAddon.HasStageAnnotation(csov1alpha1.StageAnnotationValueCreated) {
hook = "AfterControlPlaneInitialized"
hook = afterControlPlaneInitialized
} else {
hook = "BeforeClusterUpgrade"
hook = beforeClusterUpgradeHook
}

for _, stage := range clusterAddonConfig.AddonStages[hook] {
Expand Down Expand Up @@ -1332,7 +1337,7 @@ func clusterToClusterAddon(_ context.Context) handler.MapFunc {

func unTarContent(src, dst string) error {
// Create the target directory if it doesn't exist
if err := os.MkdirAll(dst, os.ModePerm); err != nil {
if err := os.MkdirAll(dst, os.ModePerm); err != nil { //nolint:gosec // ignore permissions
return fmt.Errorf("%q: creating directory: %w", dst, err)
}

Expand Down Expand Up @@ -1366,12 +1371,12 @@ func unTarContent(src, dst string) error {
switch header.Typeflag {
case tar.TypeDir:
// Create directories
if err := os.MkdirAll(targetPath, os.ModePerm); err != nil {
if err := os.MkdirAll(targetPath, os.ModePerm); err != nil { //nolint:gosec // ignore permissions
return fmt.Errorf("%q: creating directory: %w", targetPath, err)
}
case tar.TypeReg:
// Create regular files
if err := os.MkdirAll(filepath.Dir(targetPath), os.ModePerm); err != nil {
if err := os.MkdirAll(filepath.Dir(targetPath), os.ModePerm); err != nil { //nolint:gosec // ignore permissions
return fmt.Errorf("%q: creating directory: %w", filepath.Dir(targetPath), err)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/clusteraddon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ = Describe("ClusterAddonReconciler", func() {
},
}

testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
})

AfterEach(func() {
Expand Down Expand Up @@ -240,7 +240,7 @@ var _ = Describe("ClusterAddonReconciler", func() {
}, timeout, interval).Should(BeTrue())

By("checking Update method was called")
Expect(testEnv.KubeClient.AssertCalled(GinkgoT(), "Apply", mock.Anything, mock.Anything, mock.Anything)).To(BeTrue())
Expect(testEnv.KubeClient.AssertCalled(GinkgoT(), "Apply", mock.Anything, mock.Anything, mock.Anything, mock.Anything)).To(BeTrue())
})

It("should not call update if the ClusterAddon version does not change in the ClusterClass update", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/clusteraddoncreate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("ClusterAddonCreateReconciler", func() {

key = types.NamespacedName{Name: fmt.Sprintf("cluster-addon-%s", cluster.Name), Namespace: testNs.Name}

testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
})

AfterEach(func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/clusterstackrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ var _ = Describe("ClusterStackRelease validation", func() {
},
}

testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
testEnv.KubeClient.On("Apply", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]*csov1alpha1.Resource{}, false, nil)
})

AfterEach(func() {
Expand Down

0 comments on commit f44988e

Please sign in to comment.