Skip to content

Commit 773b61b

Browse files
committed
Add back test case 42543
The automation case 42543 was reverted by #1353 This PR will fix the issue on disconnected environment and added back the case which initialized by #1309
1 parent 05bd6da commit 773b61b

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,20 @@
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+
"ConnectedOnly": {},
82+
"High": {}
83+
},
84+
"resources": {
85+
"isolation": {}
86+
},
87+
"source": "openshift:payload:cluster-version-operator",
88+
"lifecycle": "blocking",
89+
"environmentSelector": {}
7590
}
7691
]
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: 65 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,60 @@ 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", "ConnectedOnly"), 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+
err = util.SkipIfNetworkRestricted(ctx, restCfg, util.FauxinnatiAPIURL)
119+
o.Expect(err).NotTo(o.HaveOccurred(), "Failed to determine if cluster is network restricted")
120+
121+
// Initialize the ocapi.OC instance
122+
g.By("Setting up oc")
123+
ocClient, err := oc.NewOC(ocapi.Options{Logger: logger, Timeout: 90 * time.Second})
124+
o.Expect(err).NotTo(o.HaveOccurred())
125+
126+
g.By("Extracting manifests in the release")
127+
annotation := "release.openshift.io/delete"
128+
tempDir, err := os.MkdirTemp("", "OTA-42543-manifest-")
129+
o.Expect(err).NotTo(o.HaveOccurred(), "create temp manifest dir failed")
130+
131+
authFile, err := util.GetAuthFile(context.Background(), kubeClient, "openshift-config", "pull-secret", ".dockerconfigjson")
132+
o.Expect(err).NotTo(o.HaveOccurred())
133+
defer func() { _ = os.Remove(authFile) }()
134+
manifestDir := ocapi.ReleaseExtractOptions{To: tempDir, AuthFile: authFile}
135+
logger.Info(fmt.Sprintf("Extract manifests to: %s", manifestDir.To))
136+
defer func() { _ = os.RemoveAll(manifestDir.To) }()
137+
err = ocClient.AdmReleaseExtract(manifestDir)
138+
o.Expect(err).NotTo(o.HaveOccurred(), "extracting manifests failed")
139+
140+
files, err := os.ReadDir(manifestDir.To)
141+
o.Expect(err).NotTo(o.HaveOccurred())
142+
g.By(fmt.Sprintf("Checking if getting manifests with %s on the cluster led to not-found error", annotation))
143+
ignore := sets.New("release-metadata", "image-references")
144+
for _, manifestFile := range files {
145+
if manifestFile.IsDir() || ignore.Has(manifestFile.Name()) {
146+
continue
147+
}
148+
filePath := filepath.Join(manifestDir.To, manifestFile.Name())
149+
o.Expect(err).NotTo(o.HaveOccurred(), "failed to read manifest file")
150+
manifests, err := manifest.ManifestsFromFiles([]string{filePath})
151+
o.Expect(err).NotTo(o.HaveOccurred(), fmt.Sprintf("failed to parse manifest file: %s", filePath))
152+
153+
for _, ms := range manifests {
154+
ann := ms.Obj.GetAnnotations()
155+
if ann[annotation] != "true" {
156+
continue
157+
}
158+
client, err := dynamicclient.New(restCfg, ms.GVK, ms.Obj.GetNamespace())
159+
o.Expect(err).NotTo(o.HaveOccurred())
160+
_, err = client.Get(ctx, ms.Obj.GetName(), metav1.GetOptions{})
161+
o.Expect(apierrors.IsNotFound(err)).To(o.BeTrue(),
162+
fmt.Sprintf("The deleted manifest should not be installed, but actually installed: manifest: %s %s in namespace %s from file %q, error: %v",
163+
ms.GVK, ms.Obj.GetName(), ms.Obj.GetNamespace(), ms.OriginalFilename, err))
164+
}
165+
}
166+
})
102167
})

0 commit comments

Comments
 (0)