Skip to content

Commit

Permalink
Compare real operator name, not prefix when checking for installed ve…
Browse files Browse the repository at this point in the history
…rsions (#1337)

* Compare real operator name, not prefix when checking for installed versions
* Unit tests to verify that.
* Add message if operator version install does not install new version

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
  • Loading branch information
ANeumann82 committed Feb 12, 2020
1 parent 62fc580 commit da8b654
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/kudoctl/util/kudo/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func InstallPackage(kc *Client, resources *packages.Resources, skipInstance bool
return fmt.Errorf("failed to install %s-operatorversion.yaml: %v", operatorName, err)
}
clog.Printf("operatorversion.%s/%s created", resources.OperatorVersion.APIVersion, resources.OperatorVersion.Name)
} else {
clog.Printf("operatorversion.%s/%s already installed", resources.OperatorVersion.APIVersion, resources.OperatorVersion.Name)
}

if skipInstance {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kudoctl/util/kudo/kudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

v1core "k8s.io/api/core/v1"
Expand Down Expand Up @@ -219,7 +218,7 @@ func (c *Client) OperatorVersionsInstalled(operatorName, namespace string) ([]st
existingVersions := []string{}

for _, v := range ov.Items {
if strings.HasPrefix(v.Name, operatorName) {
if v.Spec.Operator.Name == operatorName {
existingVersions = append(existingVersions, v.Spec.Version)
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/kudoctl/util/kudo/kudo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,14 @@ func TestKudoClient_OperatorVersionsInstalled(t *testing.T) {
},
Spec: v1beta1.OperatorVersionSpec{
Version: "1.0",
Operator: v1.ObjectReference{
Name: operatorName,
},
},
}
objWithSamePrefix := obj.DeepCopy()
objWithSamePrefix.Name = operatorName + "-demo"
objWithSamePrefix.Spec.Operator.Name = operatorName + "-demo"

installNamespace := "default"
tests := []struct {
Expand All @@ -224,6 +230,7 @@ func TestKudoClient_OperatorVersionsInstalled(t *testing.T) {
{"no operator version defined", []string{}, installNamespace, nil},
{"operator version exists in the same namespace", []string{obj.Spec.Version}, installNamespace, &obj},
{"operator version exists in different namespace", []string{}, "otherns", &obj},
{"operator with same prefix exists", []string{}, installNamespace, objWithSamePrefix},
}

for _, tt := range tests {
Expand Down

0 comments on commit da8b654

Please sign in to comment.