Skip to content

Commit

Permalink
fix: TestRedeployOnConfigChange
Browse files Browse the repository at this point in the history
Previously, the test modified the etcd-signer-ca to see if a new re-deployment would be triggered.
About two months ago, the CEO introduced a change that runs a controller which overwrites (syncs) the secret from a different source.

This change broke the test, which has been failing for nearly two months.

This PR changes the test to modify the operator's configuration,
which is fully controlled by the operator, to trigger a re-deployment.
This is what the test was originally supposed to check.
  • Loading branch information
p0lyn0mial committed Apr 16, 2024
1 parent 02d0d64 commit 013f1ec
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"encoding/json"
"fmt"
"testing"
"time"
Expand All @@ -10,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"

operatorv1client "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1"
"github.com/openshift/cluster-openshift-apiserver-operator/pkg/operator/operatorclient"
test "github.com/openshift/cluster-openshift-apiserver-operator/test/library"
operatorencryption "github.com/openshift/cluster-openshift-apiserver-operator/test/library/encryption"
Expand Down Expand Up @@ -42,31 +44,49 @@ func TestRedeployOnConfigChange(t *testing.T) {
if err != nil {
t.Fatal(err)
}
operatorClient, err := operatorv1client.NewForConfig(kubeConfig)
if err != nil {
t.Fatal(err)
}
updateOperatorUnsupportedConfigFn := func(t *testing.T, raw []byte) {
apiServerOperator, err := operatorClient.OpenShiftAPIServers().Get(ctx, "cluster", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
}
apiServerOperator.Spec.UnsupportedConfigOverrides.Raw = raw
_, err = operatorClient.OpenShiftAPIServers().Update(ctx, apiServerOperator, metav1.UpdateOptions{})
if err != nil {
t.Fatal(err)
}
}

// make sure that deployment is not in progress before and after the test
libraryapi.WaitForAPIServerToStabilizeOnTheSameRevision(t, kubeClient.CoreV1().Pods(operatorclient.TargetNamespace))
defer libraryapi.WaitForAPIServerToStabilizeOnTheSameRevision(t, kubeClient.CoreV1().Pods(operatorclient.TargetNamespace))
t.Cleanup(func() {
libraryapi.WaitForAPIServerToStabilizeOnTheSameRevision(t, kubeClient.CoreV1().Pods(operatorclient.TargetNamespace))
})

deployment, err := kubeClient.AppsV1().Deployments(operatorclient.TargetNamespace).Get(ctx, "apiserver", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
}

prevGeneration := deployment.Generation

configCMClient := kubeClient.CoreV1().ConfigMaps(operatorclient.GlobalUserSpecifiedConfigNamespace)

etcdClientCM, err := configCMClient.Get(ctx, "etcd-serving-ca", metav1.GetOptions{})
if err != nil {
t.Fatal(err)
unsupportedConfigContent := map[string]map[string][]string{
"apiServerArguments": {
"shutdown-delay-duration": []string{"17s"},
},
}
etcdClientCM.Data["some-key"] = "non-random data"

_, err = configCMClient.Update(ctx, etcdClientCM, metav1.UpdateOptions{})
rawUnsupportedConfigContent, err := json.Marshal(unsupportedConfigContent)
if err != nil {
t.Fatal(err)
}

updateOperatorUnsupportedConfigFn(t, rawUnsupportedConfigContent)
t.Cleanup(func() {
updateOperatorUnsupportedConfigFn(t, nil)
})

err = wait.PollImmediate(1*time.Second, 2*time.Minute, func() (done bool, err error) {
deployment, err := kubeClient.AppsV1().Deployments(operatorclient.TargetNamespace).Get(ctx, "apiserver", metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit 013f1ec

Please sign in to comment.