Skip to content

Commit

Permalink
UPSTREAM: <carry>: allow type mutation for specific secrets
Browse files Browse the repository at this point in the history
squash with the previous PR during the rebase
#1924
  • Loading branch information
p0lyn0mial authored and dinhxuanvu committed Apr 15, 2024
1 parent 822d173 commit 124f7a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/apis/core/validation/validation_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
"openshift-kube-apiserver-operator": {},
"openshift-kube-apiserver": {},
"openshift-kube-controller-manager-operator": {},
"openshift-config-managed": {},
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/kubernetes"
apiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
"k8s.io/kubernetes/test/integration/framework"
Expand All @@ -33,8 +34,13 @@ var whitelistedSecretNamespaces = map[string]struct{}{
"openshift-kube-apiserver-operator": {},
"openshift-kube-apiserver": {},
"openshift-kube-controller-manager-operator": {},
"openshift-config-managed": {},
}

// immortalNamespaces cannot be deleted, give the following error:
// failed to delete namespace: "" is forbidden: this namespace may not be deleted
var immortalNamespaces = sets.NewString("openshift-config-managed")

func TestOpenShiftValidateWhiteListedSecretTypeMutationUpdateAllowed(t *testing.T) {
ctx := context.Background()
server, err := apiservertesting.StartTestServer(t, apiservertesting.NewDefaultTestServerOptions(), nil, framework.SharedEtcd())
Expand All @@ -51,7 +57,9 @@ func TestOpenShiftValidateWhiteListedSecretTypeMutationUpdateAllowed(t *testing.
_, err := client.CoreV1().Namespaces().Get(ctx, whiteListedSecretNamespace, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
testNamespace := framework.CreateNamespaceOrDie(client, whiteListedSecretNamespace, t)
t.Cleanup(func() { framework.DeleteNamespaceOrDie(client, testNamespace, t) })
if !immortalNamespaces.Has(testNamespace.Name) {
t.Cleanup(func() { framework.DeleteNamespaceOrDie(client, testNamespace, t) })
}
} else if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 124f7a8

Please sign in to comment.