diff --git a/internal/policy/operator/deployable_by_olm.go b/internal/policy/operator/deployable_by_olm.go index bf0454b5c..fc8aaec74 100644 --- a/internal/policy/operator/deployable_by_olm.go +++ b/internal/policy/operator/deployable_by_olm.go @@ -28,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" apiruntime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation" ctrl "sigs.k8s.io/controller-runtime" crclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -214,6 +215,8 @@ func checkImageSource(ctx context.Context, operatorImages []string) bool { } func (p *DeployableByOlmCheck) operatorMetadata(ctx context.Context, bundleRef image.ImageReference) (*operatorData, error) { + logger := logr.FromContextOrDiscard(ctx) + // retrieve the operator metadata from bundle image annotationsFileName := filepath.Join(bundleRef.ImageFSPath, "metadata", "annotations.yaml") annotationsFile, err := os.Open(annotationsFileName) @@ -248,13 +251,21 @@ func (p *DeployableByOlmCheck) operatorMetadata(ctx context.Context, bundleRef i installModes[val.Type] = val } + // validating that package name complies with DNS-1035 labeling constraints + // ensuring that CatalogSources can be created/referenced in cluster + appName := packageName + if msgs := validation.IsDNS1035Label(packageName); len(msgs) != 0 { + logger.V(log.DBG).Info(fmt.Sprintf("package name %s does not comply with DNS-1035, prefixing to avoid errors", packageName)) + appName = "preflight-" + packageName + } + return &operatorData{ CatalogImage: catalogImage, Channel: channel, PackageName: packageName, - App: packageName, - InstallNamespace: packageName, - TargetNamespace: packageName + "-target", + App: appName, + InstallNamespace: appName, + TargetNamespace: appName + "-target", InstallModes: installModes, }, nil } diff --git a/internal/policy/operator/deployable_by_olm_test.go b/internal/policy/operator/deployable_by_olm_test.go index 99eeda6d7..63ddc42c2 100644 --- a/internal/policy/operator/deployable_by_olm_test.go +++ b/internal/policy/operator/deployable_by_olm_test.go @@ -108,8 +108,8 @@ var _ = Describe("DeployableByOLMCheck", func() { BeforeEach(func() { badSub := sub Expect(deployableByOLMCheck.client.Get(testcontext, crclient.ObjectKey{ - Name: "testPackage", - Namespace: "testPackage", + Name: "preflight-testPackage", + Namespace: "preflight-testPackage", }, &badSub)).To(Succeed()) badSub.Status.InstalledCSV = "" Expect(deployableByOLMCheck.client.Update(testcontext, &badSub, &crclient.UpdateOptions{})).To(Succeed()) diff --git a/internal/policy/operator/operator_suite_test.go b/internal/policy/operator/operator_suite_test.go index a56c25506..7212cf867 100644 --- a/internal/policy/operator/operator_suite_test.go +++ b/internal/policy/operator/operator_suite_test.go @@ -152,8 +152,8 @@ var secret = corev1.Secret{ var sub = operatorsv1alpha1.Subscription{ ObjectMeta: metav1.ObjectMeta{ - Name: "testPackage", - Namespace: "testPackage", + Name: "preflight-testPackage", + Namespace: "preflight-testPackage", }, Status: operatorsv1alpha1.SubscriptionStatus{ InstalledCSV: "csv-v0.0.0", @@ -162,8 +162,8 @@ var sub = operatorsv1alpha1.Subscription{ var og = operatorsv1.OperatorGroup{ ObjectMeta: metav1.ObjectMeta{ - Name: "testPackage", - Namespace: "testPackage", + Name: "preflight-testPackage", + Namespace: "preflight-testPackage", }, Status: operatorsv1.OperatorGroupStatus{ LastUpdated: nil,