|
7 | 7 | "net"
|
8 | 8 | "reflect"
|
9 | 9 | "testing"
|
| 10 | + "strings" |
10 | 11 | "time"
|
11 | 12 |
|
12 | 13 | "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/version"
|
@@ -923,6 +924,117 @@ func TestCatalogImageUpdate(t *testing.T) {
|
923 | 924 | subscription, err = fetchSubscription(t, crc, testNamespace, subscriptionName, subChecker)
|
924 | 925 | require.NoError(t, err)
|
925 | 926 | require.NotNil(t, subscription)
|
| 927 | + }) |
| 928 | + It("Dependency has correct replaces field", func() { |
| 929 | + // Create a CatalogSource that contains the busybox v1 and busybox-dependency v1 images |
| 930 | + // Create a Subscription for busybox v1, which has a dependency on busybox-dependency v1. |
| 931 | + // Wait for the busybox and busybox2 Subscriptions to succeed |
| 932 | + // Wait for the CSVs to succeed |
| 933 | + // Update the catalog to point to an image that contains the busybox v2 and busybox-dependency v2 images. |
| 934 | + // Wait for the new Subscriptions to succeed and check if they include the new CSVs |
| 935 | + // Wait for the CSVs to succeed and confirm that the have the correct Spec.Replaces fields. |
| 936 | + defer cleaner.NotifyTestComplete(GinkgoT(), true) |
| 937 | + |
| 938 | + sourceName := genName("catalog-") |
| 939 | + packageName := "busybox" |
| 940 | + channelName := "alpha" |
| 941 | + |
| 942 | + catSrcImage := "quay.io/olmtest/busybox-dependencies-index" |
| 943 | + |
| 944 | + // Create gRPC CatalogSource |
| 945 | + source := &v1alpha1.CatalogSource{ |
| 946 | + TypeMeta: metav1.TypeMeta{ |
| 947 | + Kind: v1alpha1.CatalogSourceKind, |
| 948 | + APIVersion: v1alpha1.CatalogSourceCRDAPIVersion, |
| 949 | + }, |
| 950 | + ObjectMeta: metav1.ObjectMeta{ |
| 951 | + Name: sourceName, |
| 952 | + Namespace: testNamespace, |
| 953 | + }, |
| 954 | + Spec: v1alpha1.CatalogSourceSpec{ |
| 955 | + SourceType: v1alpha1.SourceTypeGrpc, |
| 956 | + Image: catSrcImage + ":1.0.0", |
| 957 | + }, |
| 958 | + } |
| 959 | + |
| 960 | + crc := newCRClient(GinkgoT()) |
| 961 | + source, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Create(context.TODO(), source, metav1.CreateOptions{}) |
| 962 | + require.NoError(GinkgoT(), err) |
| 963 | + defer func() { |
| 964 | + require.NoError(GinkgoT(), crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Delete(context.TODO(), source.GetName(), metav1.DeleteOptions{})) |
| 965 | + }() |
| 966 | + |
| 967 | + // Create a Subscription for busybox |
| 968 | + subscriptionName := genName("sub-") |
| 969 | + cleanupSubscription := createSubscriptionForCatalog(GinkgoT(), crc, source.GetNamespace(), subscriptionName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic) |
| 970 | + defer cleanupSubscription() |
| 971 | + |
| 972 | + // Wait for the Subscription to succeed |
| 973 | + subscription, err := fetchSubscription(GinkgoT(), crc, testNamespace, subscriptionName, subscriptionStateAtLatestChecker) |
| 974 | + require.NoError(GinkgoT(), err) |
| 975 | + require.NotNil(GinkgoT(), subscription) |
| 976 | + require.Equal(GinkgoT(), subscription.Status.InstalledCSV, "busybox.v1.0.0") |
| 977 | + |
| 978 | + // Confirm that a subscription was created for busybox-dependency |
| 979 | + subscriptionList, err := crc.OperatorsV1alpha1().Subscriptions(source.GetNamespace()).List(context.TODO(), metav1.ListOptions{}) |
| 980 | + require.NoError(GinkgoT(), err) |
| 981 | + dependencySubscriptionName := "" |
| 982 | + for _, sub := range subscriptionList.Items { |
| 983 | + if strings.HasPrefix(sub.GetName(), "busybox-dependency") { |
| 984 | + dependencySubscriptionName = sub.GetName() |
| 985 | + } |
| 986 | + } |
| 987 | + |
| 988 | + require.NotEmpty(GinkgoT(), dependencySubscriptionName) |
| 989 | + // Wait for the Subscription to succeed |
| 990 | + subscription, err = fetchSubscription(GinkgoT(), crc, testNamespace, dependencySubscriptionName, subscriptionStateAtLatestChecker) |
| 991 | + require.NoError(GinkgoT(), err) |
| 992 | + require.NotNil(GinkgoT(), subscription) |
| 993 | + require.Equal(GinkgoT(), subscription.Status.InstalledCSV, "busybox-dependency.v1.0.0") |
| 994 | + |
| 995 | + // Update the catalog image |
| 996 | + err = wait.PollImmediate(pollInterval, pollDuration, func() (bool, error) { |
| 997 | + existingSource, err := crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Get(context.TODO(), sourceName, metav1.GetOptions{}) |
| 998 | + if err != nil { |
| 999 | + return false, err |
| 1000 | + } |
| 1001 | + existingSource.Spec.Image = catSrcImage + ":2.0.0" |
| 1002 | + |
| 1003 | + source, err = crc.OperatorsV1alpha1().CatalogSources(source.GetNamespace()).Update(context.TODO(), existingSource, metav1.UpdateOptions{}) |
| 1004 | + if err == nil { |
| 1005 | + return true, nil |
| 1006 | + } |
| 1007 | + return false, nil |
| 1008 | + }) |
| 1009 | + require.NoError(GinkgoT(), err) |
| 1010 | + |
| 1011 | + // Wait for the busybox v2 Subscription to succeed |
| 1012 | + subChecker := func(sub *v1alpha1.Subscription) bool { |
| 1013 | + return sub.Status.InstalledCSV == "busybox.v2.0.0" |
| 1014 | + } |
| 1015 | + subscription, err = fetchSubscription(GinkgoT(), crc, testNamespace, subscriptionName, subChecker) |
| 1016 | + require.NoError(GinkgoT(), err) |
| 1017 | + require.NotNil(GinkgoT(), subscription) |
| 1018 | + |
| 1019 | + // Wait for busybox v2 csv to succeed and check the replaces field |
| 1020 | + csv, err := fetchCSV(GinkgoT(), crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker) |
| 1021 | + require.NoError(GinkgoT(), err) |
| 1022 | + require.Equal(GinkgoT(), "busybox.v1.0.0", csv.Spec.Replaces) |
| 1023 | + |
| 1024 | + // Wait for the busybox-dependency v2 Subscription to succeed |
| 1025 | + subChecker = func(sub *v1alpha1.Subscription) bool { |
| 1026 | + return sub.Status.InstalledCSV == "busybox-dependency.v2.0.0" |
| 1027 | + } |
| 1028 | + subscription, err = fetchSubscription(GinkgoT(), crc, testNamespace, dependencySubscriptionName, subChecker) |
| 1029 | + require.NoError(GinkgoT(), err) |
| 1030 | + require.NotNil(GinkgoT(), subscription) |
| 1031 | + |
| 1032 | + // Wait for busybox-dependency v2 csv to succeed and check the replaces field |
| 1033 | + csv, err = fetchCSV(GinkgoT(), crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker) |
| 1034 | + require.NoError(GinkgoT(), err) |
| 1035 | + require.Equal(GinkgoT(), "busybox-dependency.v1.0.0", csv.Spec.Replaces) |
| 1036 | + }) |
| 1037 | +}) |
926 | 1038 |
|
927 | 1039 | // Wait for csv to succeed
|
928 | 1040 | csv, err := fetchCSV(t, crc, subscription.Status.CurrentCSV, subscription.GetNamespace(), csvSucceededChecker)
|
|
0 commit comments