Skip to content

Commit

Permalink
adding logic to deployablebyolm to validate that packagename complies…
Browse files Browse the repository at this point in the history
… with DNS-1035 labeling, ensuring that CatalogSources can be created

Signed-off-by: Adam D. Cornett <adc@redhat.com>
  • Loading branch information
acornett21 committed May 15, 2024
1 parent 83ee11a commit 7479ccf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/policy/operator/deployable_by_olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -248,11 +251,19 @@ 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,
App: appName,
InstallNamespace: packageName,
TargetNamespace: packageName + "-target",
InstallModes: installModes,
Expand Down

0 comments on commit 7479ccf

Please sign in to comment.