Skip to content

Commit eaf28f5

Browse files
Merge pull request #1309 from JianLi-RH/automate_42543
NO-ISSUE: OTA-1605 Automate OCP-42543
2 parents 6d31e54 + dd55880 commit eaf28f5

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

.openshift-tests-extension/openshift_payload_cluster-version-operator.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,19 @@
7272
"source": "openshift:payload:cluster-version-operator",
7373
"lifecycle": "blocking",
7474
"environmentSelector": {}
75+
},
76+
{
77+
"name": "[Jira:\"Cluster Version Operator\"] cluster-version-operator should not install resources annotated with release.openshift.io/delete=true",
78+
"labels": {
79+
"42543": {},
80+
"Conformance": {},
81+
"High": {}
82+
},
83+
"resources": {
84+
"isolation": {}
85+
},
86+
"source": "openshift:payload:cluster-version-operator",
87+
"lifecycle": "blocking",
88+
"environmentSelector": {}
7589
}
7690
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dynamicclient
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
"k8s.io/client-go/dynamic"
6+
"k8s.io/client-go/rest"
7+
8+
internaldynamicclient "github.com/openshift/cluster-version-operator/pkg/cvo/internal/dynamicclient"
9+
)
10+
11+
// New returns the resource client using a singleton factory
12+
func New(config *rest.Config, gvk schema.GroupVersionKind, namespace string) (dynamic.ResourceInterface, error) {
13+
return internaldynamicclient.New(config, gvk, namespace)
14+
}

test/cvo/cvo.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ package cvo
44

55
import (
66
"context"
7+
"fmt"
8+
"os"
9+
"path/filepath"
10+
"time"
711

812
g "github.com/onsi/ginkgo/v2"
913
o "github.com/onsi/gomega"
1014

15+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1116
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/util/sets"
1218
"k8s.io/client-go/kubernetes"
1319
"k8s.io/client-go/rest"
1420

21+
"github.com/openshift/library-go/pkg/manifest"
22+
23+
"github.com/openshift/cluster-version-operator/pkg/cvo/external/dynamicclient"
1524
"github.com/openshift/cluster-version-operator/pkg/external"
1625
"github.com/openshift/cluster-version-operator/test/oc"
1726
ocapi "github.com/openshift/cluster-version-operator/test/oc/api"
@@ -99,4 +108,54 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
99108
sccAnnotation := cvoPod.Annotations["openshift.io/scc"]
100109
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)
101110
})
111+
112+
g.It(`should not install resources annotated with release.openshift.io/delete=true`, g.Label("Conformance", "High", "42543"), func() {
113+
ctx := context.Background()
114+
err := util.SkipIfHypershift(ctx, restCfg)
115+
o.Expect(err).NotTo(o.HaveOccurred(), "Failed to determine if cluster is HyperShift")
116+
err = util.SkipIfMicroshift(ctx, restCfg)
117+
o.Expect(err).NotTo(o.HaveOccurred(), "Failed to determine if cluster is MicroShift")
118+
119+
// Initialize the ocapi.OC instance
120+
g.By("Setting up oc")
121+
ocClient, err := oc.NewOC(ocapi.Options{Logger: logger, Timeout: 90 * time.Second})
122+
o.Expect(err).NotTo(o.HaveOccurred())
123+
124+
g.By("Extracting manifests in the release")
125+
annotation := "release.openshift.io/delete"
126+
tempDir, err := os.MkdirTemp("", "OTA-42543-manifest-")
127+
o.Expect(err).NotTo(o.HaveOccurred(), "create temp manifest dir failed")
128+
manifestDir := ocapi.ReleaseExtractOptions{To: tempDir}
129+
logger.Info(fmt.Sprintf("Extract manifests to: %s", manifestDir.To))
130+
defer func() { _ = os.RemoveAll(manifestDir.To) }()
131+
err = ocClient.AdmReleaseExtract(manifestDir)
132+
o.Expect(err).NotTo(o.HaveOccurred(), "extracting manifests failed")
133+
134+
files, err := os.ReadDir(manifestDir.To)
135+
o.Expect(err).NotTo(o.HaveOccurred())
136+
g.By(fmt.Sprintf("Checking if getting manifests with %s on the cluster led to not-found error", annotation))
137+
ignore := sets.New("release-metadata", "image-references")
138+
for _, manifestFile := range files {
139+
if manifestFile.IsDir() || ignore.Has(manifestFile.Name()) {
140+
continue
141+
}
142+
filePath := filepath.Join(manifestDir.To, manifestFile.Name())
143+
o.Expect(err).NotTo(o.HaveOccurred(), "failed to read manifest file")
144+
manifests, err := manifest.ManifestsFromFiles([]string{filePath})
145+
o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("failed to parse manifest file: %s", filePath))
146+
147+
for _, ms := range manifests {
148+
ann := ms.Obj.GetAnnotations()
149+
if ann[annotation] != "true" {
150+
continue
151+
}
152+
client, err := dynamicclient.New(restCfg, ms.GVK, ms.Obj.GetNamespace())
153+
o.Expect(err).NotTo(o.HaveOccurred())
154+
_, err = client.Get(ctx, ms.Obj.GetName(), metav1.GetOptions{})
155+
o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(),
156+
fmt.Sprintf("The deleted manifest should not be installed, but actually installed: manifest: %s %s in namespace %s from file %q, error: %v",
157+
ms.GVK, ms.Obj.GetName(), ms.Obj.GetNamespace(), ms.OriginalFilename, err))
158+
}
159+
}
160+
})
102161
})

0 commit comments

Comments
 (0)