-
Notifications
You must be signed in to change notification settings - Fork 224
Add back test case 42543 #1358
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
Add back test case 42543 #1358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package dynamicclient | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/client-go/dynamic" | ||
| "k8s.io/client-go/rest" | ||
|
|
||
| internaldynamicclient "github.com/openshift/cluster-version-operator/pkg/cvo/internal/dynamicclient" | ||
| ) | ||
|
|
||
| // New returns the resource client using a singleton factory | ||
| func New(config *rest.Config, gvk schema.GroupVersionKind, namespace string) (dynamic.ResourceInterface, error) { | ||
| return internaldynamicclient.New(config, gvk, namespace) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,18 @@ package cvo | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/kubernetes" | ||
| "k8s.io/client-go/rest" | ||
|
|
||
| "github.com/openshift/cluster-version-operator/pkg/cvo/external/dynamicclient" | ||
| "github.com/openshift/cluster-version-operator/pkg/external" | ||
| "github.com/openshift/cluster-version-operator/test/oc" | ||
| ocapi "github.com/openshift/cluster-version-operator/test/oc/api" | ||
|
|
@@ -99,4 +103,48 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`, | |
| sccAnnotation := cvoPod.Annotations["openshift.io/scc"] | ||
| o.Expect(sccAnnotation).To(o.Equal("hostaccess"), "Expected the annotation 'openshift.io/scc annotation' on pod %s to have the value 'hostaccess', but got %s", cvoPod.Name, sccAnnotation) | ||
| }) | ||
|
|
||
| g.It(`should not install resources annotated with release.openshift.io/delete=true`, g.Label("Conformance", "High", "42543"), func() { | ||
| ctx := context.Background() | ||
| err := util.SkipIfHypershift(ctx, restCfg) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "Failed to determine if cluster is HyperShift") | ||
| err = util.SkipIfMicroshift(ctx, restCfg) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "Failed to determine if cluster is MicroShift") | ||
|
|
||
| pods, err := util.GetPodsByNamespace(ctx, kubeClient, external.DefaultCVONamespace, map[string]string{"k8s-app": "cluster-version-operator"}) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(pods).NotTo(o.BeEmpty(), "Expected at least one CVO pod") | ||
|
|
||
| annotation := "release.openshift.io/delete" | ||
| manifestDir := "/release-manifests/" | ||
| command := []string{"find", manifestDir, "-iname", "*.yaml", "-exec", "grep", "-l", annotation, "{}", ";"} | ||
| files, err := util.ListFilesInPodContainer(ctx, restCfg, command, external.DefaultCVONamespace, pods[0].Name, "cluster-version-operator") | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| o.Expect(files).ToNot(o.BeEmpty(), "Expected to find files in manifests directory of CVO pod, but found none") | ||
|
|
||
| for _, f := range files { | ||
| fileContent, err := util.GetFileContentInPodContainer(ctx, restCfg, external.DefaultCVONamespace, pods[0].Name, "cluster-version-operator", f) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed to get content of file %s in CVO pod", f)) | ||
| o.Expect(fileContent).ToNot(o.BeEmpty(), fmt.Sprintf("Expected to get content of file %s in CVO pod, but got empty content", f)) | ||
|
|
||
| if !strings.Contains(fileContent, annotation) { | ||
| continue | ||
| } | ||
|
|
||
| manifest, err := util.ParseManifest(fileContent) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed to parse manifest content of file %s in CVO pod", f)) | ||
|
|
||
| ann := manifest.Obj.GetAnnotations() | ||
| if ann[annotation] != "true" { | ||
| continue | ||
| } | ||
|
Comment on lines
+134
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks only one document per YAML file and can miss deleted resources.
Suggested fix direction- manifest, err := util.ParseManifest(fileContent)
- o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed to parse manifest content of file %s in CVO pod", f))
-
- ann := manifest.Obj.GetAnnotations()
- if ann[annotation] != "true" {
- continue
- }
- // check object absence ...
+ manifests, err := util.ParseManifests(fileContent) // parse all docs
+ o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("Failed to parse manifest content of file %s in CVO pod", f))
+ for _, manifest := range manifests {
+ ann := manifest.Obj.GetAnnotations()
+ if ann[annotation] != "true" {
+ continue
+ }
+ // check object absence ...
+ }🤖 Prompt for AI Agents |
||
| logger.Info("Checking file: ", f, ", GVK:", manifest.GVK.String(), ", Name: ", manifest.Obj.GetName(), ", Namespace: ", manifest.Obj.GetNamespace()) | ||
| client, err := dynamicclient.New(restCfg, manifest.GVK, manifest.Obj.GetNamespace()) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| _, err = client.Get(ctx, manifest.Obj.GetName(), metav1.GetOptions{}) | ||
| o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(), | ||
| fmt.Sprintf("The deleted manifest should not be installed, but actually installed: manifest: %s %s in namespace %s from file %q, error: %v", | ||
| manifest.GVK, manifest.Obj.GetName(), manifest.Obj.GetNamespace(), f, err)) | ||
| } | ||
| }) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard pod lookup before indexing and target a runnable CVO pod.
Line 118 dereferences
pods[0]without validating list length, and the current selection may pick a non-running pod, causing panic/flaky exec failures.Suggested fix
pods, err := util.GetPodsByNamespace(ctx, kubeClient, external.DefaultCVONamespace, map[string]string{"k8s-app": "cluster-version-operator"}) o.Expect(err).NotTo(o.HaveOccurred()) - logger.Info("CVO pod found", "name", pods[0].Name) + o.Expect(pods).NotTo(o.BeEmpty(), "Expected at least one CVO pod") + + cvoPod := pods[0] + o.Expect(cvoPod.Status.Phase).To(o.Equal(corev1.PodRunning), "Expected selected CVO pod to be Running") + logger.Info("CVO pod found", "name", cvoPod.Name) @@ - files, err := util.ListFilesInPodContainer(ctx, restCfg, command, external.DefaultCVONamespace, pods[0].Name, "cluster-version-operator") + files, err := util.ListFilesInPodContainer(ctx, restCfg, command, external.DefaultCVONamespace, cvoPod.Name, "cluster-version-operator")Also applies to: 123-124
🤖 Prompt for AI Agents