Skip to content

Commit

Permalink
Backport fix for infinite reconcile loop (#205)
Browse files Browse the repository at this point in the history
* Add observedGeneration to status to avoid infinite reconcile loop

Indirectly fixes #185

* Tests must now refresh to get the correct observedGeneration value
  • Loading branch information
jcrossley3 authored Jul 15, 2020
1 parent 97240b1 commit e73aa5e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
3 changes: 3 additions & 0 deletions config/300-eventing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ spec:
type: object
status:
properties:
observedGeneration:
description: The generation last processed by the controller
type: integer
conditions:
description: The latest available observations of a resource's current
state.
Expand Down
3 changes: 3 additions & 0 deletions config/300-serving.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ spec:
status:
description: Status defines the observed state of KnativeServing
properties:
observedGeneration:
description: The generation last processed by the controller
type: integer
conditions:
description: The latest available observations of a resource's current
state.
Expand Down
46 changes: 25 additions & 21 deletions test/resources/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,22 @@ func KSOperatorCRVerifyConfiguration(t *testing.T, clients *test.Clients, names
ks.Spec = getTestKSOperatorCRSpec()

// verify the default config map
ks = verifyDefaultConfig(t, ks, defaultsConfigMapName, clients, names)
verifyDefaultConfig(t, ks, defaultsConfigMapName, clients, names)

// verify the logging config map
verifyLoggingConfig(t, ks, loggingConfigMapName, clients, names)
verifyLoggingConfig(t, loggingConfigMapName, clients, names)

// Delete a single key/value pair
ks = verifySingleKeyDeletion(t, ks, LoggingConfigKey, loggingConfigMapName, clients, names)
verifySingleKeyDeletion(t, LoggingConfigKey, loggingConfigMapName, clients, names)

// Use an empty map as the value
ks = verifyEmptyKey(t, ks, DefaultsConfigKey, defaultsConfigMapName, clients, names)
verifyEmptyKey(t, DefaultsConfigKey, defaultsConfigMapName, clients, names)

// Now remove the config from the spec and update
verifyEmptySpec(t, ks, loggingConfigMapName, clients, names)
verifyEmptySpec(t, loggingConfigMapName, clients, names)
}

func verifyDefaultConfig(t *testing.T, ks *v1alpha1.KnativeServing, defaultsConfigMapName string, clients *test.Clients,
names test.ResourceNames) *v1alpha1.KnativeServing {
func verifyDefaultConfig(t *testing.T, ks *v1alpha1.KnativeServing, defaultsConfigMapName string, clients *test.Clients, names test.ResourceNames) {
ks, err := clients.KnativeServing().Update(ks)
if err != nil {
t.Fatalf("KnativeServing %q failed to update: %v", names.KnativeServing, err)
Expand All @@ -83,11 +82,9 @@ func verifyDefaultConfig(t *testing.T, ks *v1alpha1.KnativeServing, defaultsConf
if err != nil {
t.Fatalf("The operator failed to update %s configmap", defaultsConfigMapName)
}
return ks
}

func verifyLoggingConfig(t *testing.T, ks *v1alpha1.KnativeServing, loggingConfigMapName string, clients *test.Clients,
names test.ResourceNames) {
func verifyLoggingConfig(t *testing.T, loggingConfigMapName string, clients *test.Clients, names test.ResourceNames) {
err := WaitForConfigMap(loggingConfigMapName, clients.KubeClient.Kube, func(m map[string]string) bool {
return m["loglevel.controller"] == "debug" && m["loglevel.autoscaler"] == "debug"
})
Expand All @@ -96,10 +93,13 @@ func verifyLoggingConfig(t *testing.T, ks *v1alpha1.KnativeServing, loggingConfi
}
}

func verifySingleKeyDeletion(t *testing.T, ks *v1alpha1.KnativeServing, loggingConfigKey string,
loggingConfigMapName string, clients *test.Clients, names test.ResourceNames) *v1alpha1.KnativeServing {
func verifySingleKeyDeletion(t *testing.T, loggingConfigKey string, loggingConfigMapName string, clients *test.Clients, names test.ResourceNames) {
ks, err := clients.KnativeServing().Get(names.KnativeServing, metav1.GetOptions{})
if err != nil || ks.Spec.Config[loggingConfigKey]["loglevel.autoscaler"] == "" {
t.Fatalf("Existing KS operator CR lacks proper key: %v", ks.Spec.Config)
}
delete(ks.Spec.Config[loggingConfigKey], "loglevel.autoscaler")
ks, err := clients.KnativeServing().Update(ks)
ks, err = clients.KnativeServing().Update(ks)
if err != nil {
t.Fatalf("KnativeServing %q failed to update: %v", names.KnativeServing, err)
}
Expand All @@ -112,13 +112,15 @@ func verifySingleKeyDeletion(t *testing.T, ks *v1alpha1.KnativeServing, loggingC
if err != nil {
t.Fatalf("The operator failed to update %s configmap", loggingConfigMapName)
}
return ks
}

func verifyEmptyKey(t *testing.T, ks *v1alpha1.KnativeServing, defaultsConfigKey string,
defaultsConfigMapName string, clients *test.Clients, names test.ResourceNames) *v1alpha1.KnativeServing {
func verifyEmptyKey(t *testing.T, defaultsConfigKey string, defaultsConfigMapName string, clients *test.Clients, names test.ResourceNames) {
ks, err := clients.KnativeServing().Get(names.KnativeServing, metav1.GetOptions{})
if err != nil {
t.Fatalf("Existing KS operator CR gone: %s", names.KnativeServing)
}
ks.Spec.Config[defaultsConfigKey] = map[string]string{}
ks, err := clients.KnativeServing().Update(ks)
ks, err = clients.KnativeServing().Update(ks)
if err != nil {
t.Fatalf("KnativeServing %q failed to update: %v", names.KnativeServing, err)
}
Expand All @@ -130,16 +132,18 @@ func verifyEmptyKey(t *testing.T, ks *v1alpha1.KnativeServing, defaultsConfigKey
if err != nil {
t.Fatalf("The operator failed to update %s configmap", defaultsConfigMapName)
}
return ks
}

func verifyEmptySpec(t *testing.T, ks *v1alpha1.KnativeServing, loggingConfigMapName string, clients *test.Clients,
names test.ResourceNames) {
func verifyEmptySpec(t *testing.T, loggingConfigMapName string, clients *test.Clients, names test.ResourceNames) {
ks, err := clients.KnativeServing().Get(names.KnativeServing, metav1.GetOptions{})
if err != nil {
t.Fatalf("Existing KS operator CR gone: %s", names.KnativeServing)
}
ks.Spec = v1alpha1.KnativeServingSpec{}
if _, err := clients.KnativeServing().Update(ks); err != nil {
t.Fatalf("KnativeServing %q failed to update: %v", names.KnativeServing, err)
}
err := WaitForConfigMap(loggingConfigMapName, clients.KubeClient.Kube, func(m map[string]string) bool {
err = WaitForConfigMap(loggingConfigMapName, clients.KubeClient.Kube, func(m map[string]string) bool {
_, exists := m["loglevel.controller"]
return !exists
})
Expand Down

0 comments on commit e73aa5e

Please sign in to comment.