Skip to content

test(e2e): Fix up secret ownership checks #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions test/e2e/ownerreference_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"

Expand All @@ -25,6 +27,8 @@ const (
machineKind = "Machine"
clusterResourceSetKind = "ClusterResourceSet"
clusterResourceSetBindingKind = "ClusterResourceSetBinding"
kubeadmControlPlaneKind = "KubeadmControlPlane"
kubeadmConfigKind = "KubeadmConfig"

awsMachineKind = "AWSMachine"
awsMachineTemplateKind = "AWSMachineTemplate"
Expand Down Expand Up @@ -74,6 +78,18 @@ var (
APIVersion: caaphv1.GroupVersion.String(),
Controller: ptr.To(true),
}
kubeadmControlPlaneGroupVersion = controlplanev1.GroupVersion.String()
kubeadmControlPlaneController = metav1.OwnerReference{
Kind: kubeadmControlPlaneKind,
APIVersion: kubeadmControlPlaneGroupVersion,
Controller: ptr.To(true),
}
kubeadmConfigGroupVersion = bootstrapv1.GroupVersion.String()
kubeadmConfigController = metav1.OwnerReference{
Kind: kubeadmConfigKind,
APIVersion: kubeadmConfigGroupVersion,
Controller: ptr.To(true),
}

// AddonReferenceAssertions maps addontypes to functions which return an error if the passed OwnerReferences
// aren't as expected.
Expand Down Expand Up @@ -167,9 +183,15 @@ var (
// https://github.com/kubernetes-sigs/cluster-api/tree/main/docs/book/src/reference/owner_references.md.
KubernetesReferenceAssertions = map[string]func([]metav1.OwnerReference) error{
secretKind: func(owners []metav1.OwnerReference) error {
// TODO:deepakm-ntnx Currently pc-creds, pc-creds-for-csi, dockerhub-credentials,
// registry-creds, and encryption config secrets have unexpected owners which needs more investigation.
return nil
// Secrets for cluster certificates must be owned and controlled by the KubeadmControlPlane.
// The bootstrap secret should be owned and controlled by a KubeadmControlPlane.
// Other resources can be owned by the Cluster to ensure correct GC.
return framework.HasOneOfExactOwners(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldnt this mandate that every secret should be owned by something. there are few secrets which are not. does this test pass now?

Copy link
Contributor

@deepakm-ntnx deepakm-ntnx May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NCN-100575

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right; this check does not allow user-created Secrets in the Cluster namespace, but it needs to.

We configure CI to test only the Docker provider. I think this is the cluster spec the test uses.

AFAICT, the test does not configure registry credentials. And the Docker provider does not require credentials for any Addons (e.g. CSI, CCM). Therefore the test framework (which acts as the user here) does not create any Secrets in the Cluster namespace; CAREN does, but these Secrets are owned by the Cluster, by design.

owners,
[]metav1.OwnerReference{kubeadmControlPlaneController},
[]metav1.OwnerReference{kubeadmConfigController},
[]metav1.OwnerReference{clusterOwner},
)
},
configMapKind: func(owners []metav1.OwnerReference) error {
// The only configMaps considered here are those owned by a ClusterResourceSet.
Expand Down
Loading