Skip to content

Commit

Permalink
Merge pull request #138 from kevinrizza/Bug-1686668
Browse files Browse the repository at this point in the history
Bug 1686668: [csc] Ignore invalid values when reading `csc.Spec.Packages`
  • Loading branch information
openshift-merge-robot committed Mar 20, 2019
2 parents 68b01f6 + 84c592a commit 164d997
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
23 changes: 21 additions & 2 deletions pkg/apis/marketplace/v1alpha1/catalogsourceconfig_types.go
Expand Up @@ -100,9 +100,14 @@ func (csc *CatalogSourceConfig) EnsurePublisher() {
}
}

func (csc *CatalogSourceConfig) GetPackages() string {
pkgs := getValidPackageSliceFromString(csc.Spec.Packages)
return strings.Join(pkgs, ",")
}

// GetPackageIDs returns the list of package(s) specified.
func (csc *CatalogSourceConfig) GetPackageIDs() []string {
return strings.Split(strings.Replace(csc.Spec.Packages, " ", "", -1), ",")
return getValidPackageSliceFromString(csc.Spec.Packages)
}

// GetTargetNamespace returns the TargetNamespace where the OLM resources will
Expand All @@ -129,5 +134,19 @@ func (csc *CatalogSourceConfig) RemoveOwner(ownerUID types.UID) {

// GetPackageIDs returns the list of package(s) specified.
func (spec *CatalogSourceConfigSpec) GetPackageIDs() []string {
return strings.Split(strings.Replace(spec.Packages, " ", "", -1), ",")
return getValidPackageSliceFromString(spec.Packages)
}

func getValidPackageSliceFromString(pkgs string) []string {
pkgIds := make([]string, 0)

pkgSlice := strings.Split(strings.Replace(pkgs, " ", "", -1), ",")

for _, pkg := range pkgSlice {
if pkg != "" {
pkgIds = append(pkgIds, pkg)
}
}

return pkgIds
}
2 changes: 1 addition & 1 deletion pkg/catalogsourceconfig/cache.go
Expand Up @@ -89,7 +89,7 @@ func (c *cache) Evict(csc *v1alpha1.CatalogSourceConfig) {

func (c *cache) Set(csc *v1alpha1.CatalogSourceConfig) {
c.entries[csc.ObjectMeta.UID] = &v1alpha1.CatalogSourceConfigSpec{
Packages: csc.Spec.Packages,
Packages: csc.GetPackages(),
TargetNamespace: csc.Spec.TargetNamespace,
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/catalogsourceconfig/registry.go
Expand Up @@ -96,7 +96,7 @@ func (r *registry) GetAddress() string {
// ensureDeployment ensures that registry Deployment is present for serving
// the the grpc interface for the packages from the given operatorSources
func (r *registry) ensureDeployment(operatorSources string) error {
registryCommand := getCommand(r.csc.Spec.Packages, operatorSources)
registryCommand := getCommand(r.csc.GetPackages(), operatorSources)
deployment := new(DeploymentBuilder).WithTypeMeta().Deployment()
if err := r.client.Get(context.TODO(), r.csc.key(), deployment); err != nil {
deployment = r.newDeployment(registryCommand)
Expand Down Expand Up @@ -402,7 +402,7 @@ func (r *registry) waitForDeploymentScaleDown(retryInterval, timeout time.Durati

// getCommand returns the command used to launch the registry server
func getCommand(packages string, sources string) []string {
return []string{"appregistry-server", "-s", sources, "-o", strings.Replace(packages, " ", "", -1)}
return []string{"appregistry-server", "-s", sources, "-o", packages}
}

// getRules returns the PolicyRule needed to access the given operatorSources and secrets
Expand Down

0 comments on commit 164d997

Please sign in to comment.