Skip to content

Commit 570649e

Browse files
committed
Minor improvements to tests and handlers
1 parent 69b0d93 commit 570649e

7 files changed

Lines changed: 40 additions & 30 deletions

File tree

internal/pkg/cmd/reloader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func NewReloaderCommand() *cobra.Command {
3636
cmd.PersistentFlags().BoolVar(&options.AutoReloadAll, "auto-reload-all", false, "Auto reload all resources")
3737
cmd.PersistentFlags().StringVar(&options.ConfigmapUpdateOnChangeAnnotation, "configmap-annotation", "configmap.reloader.stakater.com/reload", "annotation to detect changes in configmaps, specified by name")
3838
cmd.PersistentFlags().StringVar(&options.SecretUpdateOnChangeAnnotation, "secret-annotation", "secret.reloader.stakater.com/reload", "annotation to detect changes in secrets, specified by name")
39-
cmd.PersistentFlags().StringVar(&options.SecretProviderClassUpdateOnChangeAnnotation, "spc-annotation", "secretproviderclass.reloader.stakater.com/reload", "annotation to detect changes in secretproviderclasses, specified by name")
39+
cmd.PersistentFlags().StringVar(&options.SecretProviderClassUpdateOnChangeAnnotation, "secretproviderclass-annotation", "secretproviderclass.reloader.stakater.com/reload", "annotation to detect changes in secretproviderclasses, specified by name")
4040
cmd.PersistentFlags().StringVar(&options.ReloaderAutoAnnotation, "auto-annotation", "reloader.stakater.com/auto", "annotation to detect changes in secrets/configmaps")
4141
cmd.PersistentFlags().StringVar(&options.ConfigmapReloaderAutoAnnotation, "configmap-auto-annotation", "configmap.reloader.stakater.com/auto", "annotation to detect changes in configmaps")
4242
cmd.PersistentFlags().StringVar(&options.SecretReloaderAutoAnnotation, "secret-auto-annotation", "secret.reloader.stakater.com/auto", "annotation to detect changes in secrets")
43-
cmd.PersistentFlags().StringVar(&options.SecretProviderClassReloaderAutoAnnotation, "spc-auto-annotation", "secretproviderclass.reloader.stakater.com/auto", "annotation to detect changes in secretproviderclasses")
43+
cmd.PersistentFlags().StringVar(&options.SecretProviderClassReloaderAutoAnnotation, "secretproviderclass-auto-annotation", "secretproviderclass.reloader.stakater.com/auto", "annotation to detect changes in secretproviderclasses")
4444
cmd.PersistentFlags().StringVar(&options.AutoSearchAnnotation, "auto-search-annotation", "reloader.stakater.com/search", "annotation to detect changes in configmaps or secrets tagged with special match annotation")
4545
cmd.PersistentFlags().StringVar(&options.SearchMatchAnnotation, "search-match-annotation", "reloader.stakater.com/match", "annotation to mark secrets or configmaps to match the search")
4646
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON)")
@@ -184,7 +184,7 @@ func startReloader(cmd *cobra.Command, args []string) {
184184
continue
185185
}
186186
if !kube.IsCSIInstalled {
187-
logrus.Infof("Can't run CSI controller as CSI CRDs are not installed")
187+
logrus.Infof("Can't run secretproviderclasspodstatuses controller as CSI CRDs are not installed")
188188
continue
189189
}
190190
}

internal/pkg/constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const (
88
ConfigmapEnvVarPostfix = "CONFIGMAP"
99
// SecretEnvVarPostfix is a postfix for secret envVar
1010
SecretEnvVarPostfix = "SECRET"
11-
// SecretEnvVarSecretProviderClassPodStatus is a postfix for secretproviderclasspodstatus envVar
11+
// SecretProviderClassEnvVarPostfix is a postfix for secretproviderclasspodstatus envVar
1212
SecretProviderClassEnvVarPostfix = "SECRETPROVIDERCLASS"
1313
// EnvVarPrefix is a Prefix for environment variable
1414
EnvVarPrefix = "STAKATER_"

internal/pkg/controller/controller.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"k8s.io/client-go/util/workqueue"
2323
"k8s.io/kubectl/pkg/scheme"
2424
"k8s.io/utils/strings/slices"
25+
csiv1 "sigs.k8s.io/secrets-store-csi-driver/apis/v1"
2526
)
2627

2728
// Controller for checking events
@@ -117,6 +118,8 @@ func (c *Controller) Add(obj interface{}) {
117118
case *v1.Namespace:
118119
c.addSelectedNamespaceToCache(*object)
119120
return
121+
case *csiv1.SecretProviderClassPodStatus:
122+
return
120123
}
121124

122125
if options.ReloadOnCreate == "true" {
@@ -136,6 +139,8 @@ func (c *Controller) resourceInIgnoredNamespace(raw interface{}) bool {
136139
return c.ignoredNamespaces.Contains(object.ObjectMeta.Namespace)
137140
case *v1.Secret:
138141
return c.ignoredNamespaces.Contains(object.ObjectMeta.Namespace)
142+
case *csiv1.SecretProviderClassPodStatus:
143+
return c.ignoredNamespaces.Contains(object.ObjectMeta.Namespace)
139144
}
140145
return false
141146
}
@@ -154,6 +159,10 @@ func (c *Controller) resourceInSelectedNamespaces(raw interface{}) bool {
154159
if slices.Contains(selectedNamespacesCache, object.GetNamespace()) {
155160
return true
156161
}
162+
case *csiv1.SecretProviderClassPodStatus:
163+
if slices.Contains(selectedNamespacesCache, object.GetNamespace()) {
164+
return true
165+
}
157166
}
158167
return false
159168
}
@@ -192,6 +201,13 @@ func (c *Controller) Update(old interface{}, new interface{}) {
192201

193202
// Delete function to add an object to the queue in case of deleting a resource
194203
func (c *Controller) Delete(old interface{}) {
204+
switch object := old.(type) {
205+
case *v1.Namespace:
206+
c.removeSelectedNamespaceFromCache(*object)
207+
return
208+
case *csiv1.SecretProviderClassPodStatus:
209+
return
210+
}
195211

196212
if options.ReloadOnDelete == "true" {
197213
if !c.resourceInIgnoredNamespace(old) && c.resourceInSelectedNamespaces(old) && secretControllerInitialized && configmapControllerInitialized {
@@ -202,12 +218,6 @@ func (c *Controller) Delete(old interface{}) {
202218
})
203219
}
204220
}
205-
206-
switch object := old.(type) {
207-
case *v1.Namespace:
208-
c.removeSelectedNamespaceFromCache(*object)
209-
return
210-
}
211221
}
212222

213223
// Run function for controller which handles the queue

internal/pkg/controller/controller_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusShouldCreatePodAnnotation
649649
return
650650
}
651651

652-
// Creating secretclassprovider
652+
// Creating secretproviderclass
653653
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
654654
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
655655
if err != nil {
656-
t.Errorf("Error while creating the secretclassprovider %v", err)
656+
t.Errorf("Error while creating the secretproviderclass %v", err)
657657
}
658658

659659
// Creating secretproviderclasspodstatus
@@ -718,11 +718,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusShouldUpdatePodAnnotation
718718
return
719719
}
720720

721-
// Creating secretclassprovider
721+
// Creating secretproviderclass
722722
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
723723
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
724724
if err != nil {
725-
t.Errorf("Error while creating the secretclassprovider %v", err)
725+
t.Errorf("Error while creating the secretproviderclass %v", err)
726726
}
727727

728728
// Creating secretproviderclasspodstatus
@@ -793,11 +793,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusWithSameDataShouldNotCrea
793793
return
794794
}
795795

796-
// Creating secretclassprovider
796+
// Creating secretproviderclass
797797
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
798798
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
799799
if err != nil {
800-
t.Errorf("Error while creating the secretclassprovider %v", err)
800+
t.Errorf("Error while creating the secretproviderclass %v", err)
801801
}
802802

803803
// Creating secretproviderclasspodstatus
@@ -829,7 +829,7 @@ func TestControllerUpdatingSecretProviderClassPodStatusWithSameDataShouldNotCrea
829829
deploymentFuncs := handler.GetDeploymentRollingUpgradeFuncs()
830830
updated := testutil.VerifyResourceAnnotationUpdate(clients, config, deploymentFuncs)
831831
if updated {
832-
t.Errorf("Deployment should not be updated by changing in secret")
832+
t.Errorf("Deployment should not be updated by changing in secretproviderclasspodstatus")
833833
}
834834

835835
// Deleting Deployment
@@ -1870,11 +1870,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusShouldCreateEnvInDeployme
18701870
return
18711871
}
18721872

1873-
// Creating secretclassprovider
1873+
// Creating secretproviderclass
18741874
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
18751875
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
18761876
if err != nil {
1877-
t.Errorf("Error while creating the secretclassprovider %v", err)
1877+
t.Errorf("Error while creating the secretproviderclass %v", err)
18781878
}
18791879

18801880
// Creating secretproviderclasspodstatus
@@ -1938,11 +1938,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusShouldUpdateEnvInDeployme
19381938
return
19391939
}
19401940

1941-
// Creating secretclassprovider
1941+
// Creating secretproviderclass
19421942
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
19431943
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
19441944
if err != nil {
1945-
t.Errorf("Error while creating the secretclassprovider %v", err)
1945+
t.Errorf("Error while creating the secretproviderclass %v", err)
19461946
}
19471947

19481948
// Creating secretproviderclasspodstatus
@@ -2012,11 +2012,11 @@ func TestControllerUpdatingSecretProviderClassPodStatusLabelsShouldNotCreateOrUp
20122012
return
20132013
}
20142014

2015-
// Creating secretclassprovider
2015+
// Creating secretproviderclass
20162016
secretproviderclasspodstatusName := secretProviderClassPodStatusPrefix + "-update-" + testutil.RandSeq(5)
20172017
_, err := testutil.CreateSecretProviderClass(clients.CSIClient, namespace, secretproviderclasspodstatusName, data)
20182018
if err != nil {
2019-
t.Errorf("Error while creating the secretclassprovider %v", err)
2019+
t.Errorf("Error while creating the secretproviderclass %v", err)
20202020
}
20212021

20222022
// Creating secretproviderclasspodstatus
@@ -2033,7 +2033,7 @@ func TestControllerUpdatingSecretProviderClassPodStatusLabelsShouldNotCreateOrUp
20332033

20342034
err = testutil.UpdateSecretProviderClassPodStatus(spcpsClient, namespace, secretproviderclasspodstatusName, "test", data)
20352035
if err != nil {
2036-
t.Errorf("Error while updating secret %v", err)
2036+
t.Errorf("Error while updating secretproviderclasspodstatus %v", err)
20372037
}
20382038

20392039
// Verifying Upgrade
@@ -2048,7 +2048,7 @@ func TestControllerUpdatingSecretProviderClassPodStatusLabelsShouldNotCreateOrUp
20482048
deploymentFuncs := handler.GetDeploymentRollingUpgradeFuncs()
20492049
updated := testutil.VerifyResourceEnvVarUpdate(clients, config, constants.SecretProviderClassEnvVarPostfix, deploymentFuncs)
20502050
if updated {
2051-
t.Errorf("Deployment should not be updated by changing label in secret")
2051+
t.Errorf("Deployment should not be updated by changing label in secretproviderclasspodstatus")
20522052
}
20532053

20542054
// Deleting Deployment

internal/pkg/handler/upgrade_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@ func TestRollingUpgradeForDaemonSetWithSecretProviderClassUsingArs(t *testing.T)
28092809
envVarPostfix := constants.SecretProviderClassEnvVarPostfix
28102810

28112811
shaData := testutil.ConvertResourceToSHA(testutil.SecretProviderClassPodStatusResourceType, arsNamespace, arsSecretProviderClassName, "testing1")
2812-
config := getConfigWithAnnotations(envVarPostfix, arsSecretProviderClassName, shaData, options.SecretUpdateOnChangeAnnotation, options.SecretReloaderAutoAnnotation)
2812+
config := getConfigWithAnnotations(envVarPostfix, arsSecretProviderClassName, shaData, options.SecretProviderClassUpdateOnChangeAnnotation, options.SecretProviderClassReloaderAutoAnnotation)
28132813
daemonSetFuncs := GetDaemonSetRollingUpgradeFuncs()
28142814
collectors := getCollectors()
28152815

@@ -2969,7 +2969,7 @@ func TestRollingUpgradeForStatefulSetWithSecretProviderClassUsingArs(t *testing.
29692969
envVarPostfix := constants.SecretProviderClassEnvVarPostfix
29702970

29712971
shaData := testutil.ConvertResourceToSHA(testutil.SecretProviderClassPodStatusResourceType, arsNamespace, arsSecretProviderClassName, "testing1")
2972-
config := getConfigWithAnnotations(envVarPostfix, arsSecretProviderClassName, shaData, options.SecretUpdateOnChangeAnnotation, options.SecretReloaderAutoAnnotation)
2972+
config := getConfigWithAnnotations(envVarPostfix, arsSecretProviderClassName, shaData, options.SecretProviderClassUpdateOnChangeAnnotation, options.SecretProviderClassReloaderAutoAnnotation)
29732973
statefulSetFuncs := GetStatefulSetRollingUpgradeFuncs()
29742974
collectors := getCollectors()
29752975

@@ -3776,7 +3776,7 @@ func TestRollingUpgradeForDeploymentWithSecretProviderClassExcludeAnnotationUsin
37763776
err := PerformAction(clients, config, deploymentFuncs, collectors, nil, invokeReloadStrategy)
37773777
time.Sleep(5 * time.Second)
37783778
if err != nil {
3779-
t.Errorf("Rolling upgrade failed for Deployment with exclude Secret")
3779+
t.Errorf("Rolling upgrade failed for Deployment with exclude SecretProviderClass")
37803780
}
37813781

37823782
logrus.Infof("Verifying deployment did not update")

internal/pkg/options/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var (
6262
EnableHA = false
6363
// Url to send a request to instead of triggering a reload
6464
WebhookUrl = ""
65-
// EnableCsiIntegration Adds support to watch SecretProviderClassPodStatus and restart deployment based on it
65+
// EnableCSIIntegration Adds support to watch SecretProviderClassPodStatus and restart deployment based on it
6666
EnableCSIIntegration = false
6767
)
6868

internal/pkg/testutil/kube.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ func CreateSecretProviderClass(client csiclient.Interface, namespace string, sec
845845
return secretProviderClassClient, err
846846
}
847847

848-
// CreateSecretProviderClass creates a SecretProviderClassPodStatus in given namespace and returns the SecretProviderClassInterface
848+
// CreateSecretProviderClassPodStatus creates a SecretProviderClassPodStatus in given namespace and returns the SecretProviderClassPodStatusInterface
849849
func CreateSecretProviderClassPodStatus(client csiclient.Interface, namespace string, secretProviderClassPodStatusName string, data string) (csiclient_v1.SecretProviderClassPodStatusInterface, error) {
850850
logrus.Infof("Creating SecretProviderClassPodStatus")
851851
secretProviderClassPodStatusClient := client.SecretsstoreV1().SecretProviderClassPodStatuses(namespace)

0 commit comments

Comments
 (0)