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