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