Skip to content

Commit 37dcff4

Browse files
perdasilvaPer Goncalves da Silva
and
Per Goncalves da Silva
authored
🌱 update skopeo openshift test (#3298)
* update skopeo openshift test Signed-off-by: Per Goncalves da Silva <[email protected]> * patch subscription e2e flake Signed-off-by: Per Goncalves da Silva <[email protected]> --------- Signed-off-by: Per Goncalves da Silva <[email protected]> Co-authored-by: Per Goncalves da Silva <[email protected]>
1 parent 01b44e8 commit 37dcff4

File tree

3 files changed

+69
-50
lines changed

3 files changed

+69
-50
lines changed

test/e2e/catalog_e2e_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
820820

821821
By("Create an image based catalog source from public Quay image using a unique tag as identifier")
822822
var registryURL string
823-
var registryAuth string
823+
var registryAuthSecretName string
824824
if local {
825825
By("Creating a local registry to use")
826826
registryURL, err = createDockerRegistry(c, generatedNamespace.GetName())
@@ -836,7 +836,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
836836
} else {
837837
registryURL = fmt.Sprintf("%s/%s", openshiftregistryFQDN, generatedNamespace.GetName())
838838
By("Using the OpenShift registry at " + registryURL)
839-
registryAuth, err = openshiftRegistryAuth(c, generatedNamespace.GetName())
839+
registryAuthSecretName, err = getRegistryAuthSecretName(c, generatedNamespace.GetName())
840840
Expect(err).NotTo(HaveOccurred(), "error getting openshift registry authentication: %s", err)
841841
}
842842

@@ -853,8 +853,8 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
853853
Expect(err).NotTo(HaveOccurred(), "error copying old registry file: %s", err)
854854
} else {
855855
By("creating a skopoeo Pod to do the copying")
856-
skopeoArgs := skopeoCopyCmd(testImage, tag, catsrcImage, "old", registryAuth)
857-
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName())
856+
skopeoArgs := skopeoCopyCmd(testImage, tag, catsrcImage, "old", registryAuthSecretName)
857+
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName(), registryAuthSecretName)
858858
Expect(err).NotTo(HaveOccurred(), "error creating skopeo pod: %s", err)
859859

860860
By("waiting for the skopeo pod to exit successfully")
@@ -948,8 +948,8 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
948948
Expect(err).NotTo(HaveOccurred(), "error copying new registry file: %s", err)
949949
} else {
950950
By("creating a skopoeo Pod to do the copying")
951-
skopeoArgs := skopeoCopyCmd(testImage, tag, catsrcImage, "new", registryAuth)
952-
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName())
951+
skopeoArgs := skopeoCopyCmd(testImage, tag, catsrcImage, "new", registryAuthSecretName)
952+
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName(), registryAuthSecretName)
953953
Expect(err).NotTo(HaveOccurred(), "error creating skopeo pod: %s", err)
954954

955955
By("waiting for the skopeo pod to exit successfully")

test/e2e/skopeo.go

+49-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os/exec"
7+
"path"
78

89
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
910
"k8s.io/utils/ptr"
@@ -18,14 +19,15 @@ const (
1819
debug = "--debug"
1920
skipTLS = "--dest-tls-verify=false"
2021
skipCreds = "--dest-no-creds=true"
21-
destCreds = "--dest-creds="
22+
destCreds = "--dest-authfile="
2223
v2format = "--format=v2s2"
23-
skopeoImage = "quay.io/olmtest/skopeo:0.1.40"
24+
skopeoImage = "quay.io/skopeo/stable:v1.15.0"
2425
BuilderServiceAccount = "builder"
26+
authPath = "/mnt/registry-auth"
27+
cachePath = ".local"
2528
)
2629

27-
func openshiftRegistryAuth(client operatorclient.ClientInterface, namespace string) (string, error) {
28-
30+
func getRegistryAuthSecretName(client operatorclient.ClientInterface, namespace string) (string, error) {
2931
var sa *corev1.ServiceAccount
3032
var err error
3133

@@ -47,15 +49,7 @@ func openshiftRegistryAuth(client operatorclient.ClientInterface, namespace stri
4749
if err != nil {
4850
return "", err
4951
}
50-
annotations := secret.Annotations
51-
if annotations == nil {
52-
return "", fmt.Errorf("annotations not present on builder secret")
53-
}
54-
55-
user := annotations["openshift.io/token-secret.name"]
56-
pass := annotations["openshift.io/token-secret.value"]
57-
58-
return fmt.Sprint(user, ":", pass), nil
52+
return secret.GetName(), nil
5953
}
6054

6155
func skopeoCopyCmd(newImage, newTag, oldImage, oldTag, auth string) []string {
@@ -66,15 +60,15 @@ func skopeoCopyCmd(newImage, newTag, oldImage, oldTag, auth string) []string {
6660
if auth == "" {
6761
creds = skipCreds
6862
} else {
69-
creds = fmt.Sprint(destCreds, auth)
63+
creds = fmt.Sprint(destCreds, path.Join(cachePath, "auth.json"))
7064
}
7165

7266
cmd := []string{debug, insecure, "copy", skipTLS, v2format, creds, oldImageName, newImageName}
7367

7468
return cmd
7569
}
7670

77-
func createSkopeoPod(client operatorclient.ClientInterface, args []string, namespace string) error {
71+
func createSkopeoPod(client operatorclient.ClientInterface, args []string, namespace string, registrySecret string) error {
7872
pod := &corev1.Pod{
7973
ObjectMeta: metav1.ObjectMeta{
8074
Name: skopeo,
@@ -93,12 +87,12 @@ func createSkopeoPod(client operatorclient.ClientInterface, args []string, names
9387
Image: skopeoImage,
9488
Args: args,
9589
SecurityContext: &corev1.SecurityContext{
96-
ReadOnlyRootFilesystem: ptr.To(bool(false)),
97-
AllowPrivilegeEscalation: ptr.To(bool(false)),
90+
ReadOnlyRootFilesystem: ptr.To(false),
91+
AllowPrivilegeEscalation: ptr.To(false),
9892
Capabilities: &corev1.Capabilities{
9993
Drop: []corev1.Capability{"ALL"},
10094
},
101-
RunAsNonRoot: ptr.To(bool(true)),
95+
RunAsNonRoot: ptr.To(true),
10296
RunAsUser: ptr.To(int64(1001)),
10397
},
10498
},
@@ -108,6 +102,43 @@ func createSkopeoPod(client operatorclient.ClientInterface, args []string, names
108102
},
109103
}
110104

105+
if registrySecret != "" {
106+
// update container command to first convert the dockercfg to an auth.json file that skopeo can use
107+
authJsonPath := path.Join(cachePath, "auth.json")
108+
authJson := "\"{\\\"auths\\\": $(cat /mnt/registry-auth/.dockercfg)}\""
109+
cmd := fmt.Sprintf("echo %s > %s && exec skopeo $@", authJson, authJsonPath)
110+
111+
pod.Spec.Containers[0].Command = []string{"bash", "-c", cmd}
112+
113+
pod.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{
114+
{
115+
Name: "registry-auth",
116+
MountPath: authPath,
117+
ReadOnly: true,
118+
}, {
119+
Name: "cache",
120+
MountPath: cachePath,
121+
ReadOnly: false,
122+
},
123+
}
124+
pod.Spec.Volumes = []corev1.Volume{
125+
{
126+
Name: "registry-auth",
127+
VolumeSource: corev1.VolumeSource{
128+
Secret: &corev1.SecretVolumeSource{
129+
SecretName: registrySecret,
130+
},
131+
},
132+
},
133+
{
134+
Name: "cache",
135+
VolumeSource: corev1.VolumeSource{
136+
EmptyDir: &corev1.EmptyDirVolumeSource{},
137+
},
138+
},
139+
}
140+
}
141+
111142
_, err := client.KubernetesInterface().CoreV1().Pods(namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
112143
if err != nil {
113144
return err

test/e2e/subscription_e2e_test.go

+14-26
Original file line numberDiff line numberDiff line change
@@ -2597,19 +2597,24 @@ var _ = Describe("Subscription", func() {
25972597
err = magicCatalog.UpdateCatalog(context.Background(), provider)
25982598
Expect(err).To(BeNil())
25992599

2600-
By("waiting for the subscription to have v0.3.0 installed")
2600+
By("waiting for the subscription to switch to v0.3.0")
26012601
sub, err = fetchSubscription(crc, generatedNamespace.GetName(), subName, subscriptionHasCurrentCSV("example-operator.v0.3.0"))
26022602
Expect(err).Should(BeNil())
26032603

2604-
By("waiting for the subscription to have v0.3.0 installed with a Package deprecated condition")
2604+
By("waiting for the subscription to have be at latest known")
2605+
sub, err = fetchSubscription(crc, generatedNamespace.GetName(), subName, subscriptionStateAtLatestChecker())
2606+
Expect(err).Should(BeNil())
2607+
2608+
By("waiting for the subscription to have v0.3.0 installed without a bundle deprecated condition")
26052609
sub, err = fetchSubscription(crc, generatedNamespace.GetName(), subName,
26062610
subscriptionHasCondition(
2607-
operatorsv1alpha1.SubscriptionPackageDeprecated,
2608-
corev1.ConditionTrue,
2611+
operatorsv1alpha1.SubscriptionInstallPlanPending,
2612+
corev1.ConditionUnknown,
2613+
"",
26092614
"",
2610-
"olm.package/test-package: test-package has been deprecated. Please switch to another-package.",
26112615
),
26122616
)
2617+
Expect(err).Should(BeNil())
26132618

26142619
By("checking for the deprecated conditions")
26152620
By(`Operator is deprecated at only Package and Channel levels`)
@@ -2705,7 +2710,7 @@ var _ = Describe("Subscription", func() {
27052710
}
27062711
} else {
27072712
registryURL = fmt.Sprintf("%s/%s", openshiftregistryFQDN, generatedNamespace.GetName())
2708-
registryAuth, err := openshiftRegistryAuth(c, generatedNamespace.GetName())
2713+
registryAuthSecretName, err := getRegistryAuthSecretName(c, generatedNamespace.GetName())
27092714
Expect(err).NotTo(HaveOccurred(), "error getting openshift registry authentication: %s", err)
27102715
copyImage = func(dst, dstTag, src, srcTag string) error {
27112716
if !strings.HasPrefix(src, "docker://") {
@@ -2714,14 +2719,15 @@ var _ = Describe("Subscription", func() {
27142719
if !strings.HasPrefix(dst, "docker://") {
27152720
dst = fmt.Sprintf("docker://%s", dst)
27162721
}
2717-
skopeoArgs := skopeoCopyCmd(dst, dstTag, src, srcTag, registryAuth)
2718-
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName())
2722+
skopeoArgs := skopeoCopyCmd(dst, dstTag, src, srcTag, registryAuthSecretName)
2723+
err = createSkopeoPod(c, skopeoArgs, generatedNamespace.GetName(), registryAuthSecretName)
27192724
if err != nil {
27202725
return fmt.Errorf("error creating skopeo pod: %v", err)
27212726
}
27222727

27232728
By(`wait for skopeo pod to exit successfully`)
27242729
awaitPod(GinkgoT(), c, generatedNamespace.GetName(), skopeo, func(pod *corev1.Pod) bool {
2730+
ctx.Ctx().Logf("skopeo pod status: %s (waiting for: %s)", pod.Status.Phase, corev1.PodSucceeded)
27252731
return pod.Status.Phase == corev1.PodSucceeded
27262732
})
27272733

@@ -3627,12 +3633,6 @@ func updateInternalCatalog(t GinkgoTInterface, c operatorclient.ClientInterface,
36273633
require.NoError(t, err)
36283634
}
36293635

3630-
func updateCatSrcPriority(crClient versioned.Interface, namespace string, catsrc *operatorsv1alpha1.CatalogSource, priority int) {
3631-
catsrc.Spec.Priority = priority
3632-
_, err := crClient.OperatorsV1alpha1().CatalogSources(namespace).Update(context.Background(), catsrc, metav1.UpdateOptions{})
3633-
Expect(err).Should(BeNil())
3634-
}
3635-
36363636
func subscriptionCurrentCSVGetter(crclient versioned.Interface, namespace, subName string) func() string {
36373637
return func() string {
36383638
subscription, err := crclient.OperatorsV1alpha1().Subscriptions(namespace).Get(context.Background(), subName, metav1.GetOptions{})
@@ -3642,15 +3642,3 @@ func subscriptionCurrentCSVGetter(crclient versioned.Interface, namespace, subNa
36423642
return subscription.Status.CurrentCSV
36433643
}
36443644
}
3645-
3646-
func operatorGroupServiceAccountNameSetter(crclient versioned.Interface, namespace, name, saName string) func() error {
3647-
return func() error {
3648-
toUpdate, err := crclient.OperatorsV1().OperatorGroups(namespace).Get(context.Background(), name, metav1.GetOptions{})
3649-
if err != nil {
3650-
return err
3651-
}
3652-
toUpdate.Spec.ServiceAccountName = saName
3653-
_, err = crclient.OperatorsV1().OperatorGroups(namespace).Update(context.Background(), toUpdate, metav1.UpdateOptions{})
3654-
return err
3655-
}
3656-
}

0 commit comments

Comments
 (0)