Skip to content

Commit

Permalink
Merge pull request #1094 from dinhxuanvu/minkube-status-fix
Browse files Browse the repository at this point in the history
fix(olm): No longer report status if minKubeVersion not specified
  • Loading branch information
openshift-merge-robot authored Oct 30, 2019
2 parents 3255734 + 08e61fd commit 190fc72
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 12 deletions.
19 changes: 10 additions & 9 deletions pkg/controller/operators/olm/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ import (
)

func (a *Operator) minKubeVersionStatus(name string, minKubeVersion string) (met bool, statuses []v1alpha1.RequirementStatus) {
if minKubeVersion == "" {
return true, nil
}

status := v1alpha1.RequirementStatus{
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: name,
}

if minKubeVersion == "" {
status.Status = v1alpha1.RequirementStatusReasonNotPresent
status.Message = "CSV missing minimum kube version specification"
met = true
statuses = append(statuses, status)
return
}

// Retrieve server k8s version
serverVersionInfo, err := a.opClient.KubernetesInterface().Discovery().ServerVersion()
if err != nil {
Expand Down Expand Up @@ -340,6 +336,7 @@ func (a *Operator) permissionStatus(strategyDetailsDeployment *install.StrategyD

// requirementAndPermissionStatus returns the aggregate requirement and permissions statuses for the given CSV
func (a *Operator) requirementAndPermissionStatus(csv *v1alpha1.ClusterServiceVersion) (bool, []v1alpha1.RequirementStatus, error) {
allReqStatuses := []v1alpha1.RequirementStatus{}
// Use a StrategyResolver to unmarshal
strategyResolver := install.StrategyResolver{}
strategy, err := strategyResolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
Expand All @@ -355,8 +352,12 @@ func (a *Operator) requirementAndPermissionStatus(csv *v1alpha1.ClusterServiceVe

// Check kubernetes version requirement between CSV and server
minKubeMet, minKubeStatus := a.minKubeVersionStatus(csv.GetName(), csv.Spec.MinKubeVersion)
if minKubeStatus != nil {
allReqStatuses = append(allReqStatuses, minKubeStatus...)
}

reqMet, reqStatuses := a.requirementStatus(strategyDetailsDeployment, csv.GetAllCRDDescriptions(), csv.GetOwnedAPIServiceDescriptions(), csv.GetRequiredAPIServiceDescriptions(), csv.Spec.NativeAPIs)
allReqStatuses := append(minKubeStatus, reqStatuses...)
allReqStatuses = append(allReqStatuses, reqStatuses...)

rbacLister := a.lister.RbacV1()
roleLister := rbacLister.RoleLister()
Expand Down
104 changes: 101 additions & 3 deletions pkg/controller/operators/olm/requirements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
nil,
v1alpha1.CSVPhasePending,
),
existingObjs: nil,
existingExtObjs: nil,
met: false,
existingObjs: nil,
existingExtObjs: nil,
met: false,
expectedRequirementStatuses: nil,
expectedError: fmt.Errorf("unexpected end of JSON input"),
},
Expand Down Expand Up @@ -637,3 +637,101 @@ func TestRequirementAndPermissionStatus(t *testing.T) {
})
}
}

func TestMinKubeVersionStatus(t *testing.T) {
namespace := "ns"
csv := csv("csv1",
namespace,
"0.0.0",
"",
v1alpha1.NamedInstallStrategy{"deployment", json.RawMessage{}},
nil,
nil,
v1alpha1.CSVPhasePending,
)

tests := []struct {
description string
csvName string
minKubeVersion string
expectedMet bool
expectedRequirementStatuses []v1alpha1.RequirementStatus
}{
{
description: "minKubeVersion is not specfied",
csvName: "test1",
minKubeVersion: "",
expectedMet: true,
expectedRequirementStatuses: []v1alpha1.RequirementStatus{},
},
{
description: "minKubeVersion is met",
csvName: "test2",
minKubeVersion: "0.0.0",
expectedMet: true,
expectedRequirementStatuses: []v1alpha1.RequirementStatus{
v1alpha1.RequirementStatus{
Status: v1alpha1.RequirementStatusReasonPresent,
Message: fmt.Sprintf("CSV minKubeVersion (%s) less than server version", "0.0.0"),
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: "test2",
},
},
},
{
description: "minKubeVersion is unmet",
csvName: "test3",
minKubeVersion: "999.999.999",
expectedMet: false,
expectedRequirementStatuses: []v1alpha1.RequirementStatus{
v1alpha1.RequirementStatus{
Status: v1alpha1.RequirementStatusReasonPresentNotSatisfied,
Message: fmt.Sprintf("CSV version requirement not met: minKubeVersion (%s)", "999.999.999"),
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: "test3",
},
},
},
{
description: "minKubeVersion is invalid",
csvName: "test4",
minKubeVersion: "a.b.c",
expectedMet: false,
expectedRequirementStatuses: []v1alpha1.RequirementStatus{
v1alpha1.RequirementStatus{
Status: v1alpha1.RequirementStatusReasonPresentNotSatisfied,
Message: "CSV version parsing error",
Group: "operators.coreos.com",
Version: "v1alpha1",
Kind: "ClusterServiceVersion",
Name: "test4",
},
},
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
op, err := NewFakeOperator(ctx, withNamespaces(namespace), withOperatorNamespace(namespace), withClientObjs(csv))
require.NoError(t, err)

// Get the permission status
met, status := op.minKubeVersionStatus(test.csvName, test.minKubeVersion)
require.Equal(t, test.expectedMet, met)
if len(test.expectedRequirementStatuses) > 0 {
require.Equal(t, status[0].Status, test.expectedRequirementStatuses[0].Status)
require.Equal(t, status[0].Kind, test.expectedRequirementStatuses[0].Kind)
require.Equal(t, status[0].Name, test.expectedRequirementStatuses[0].Name)
require.Contains(t, status[0].Message, test.expectedRequirementStatuses[0].Message)
} else {
require.Equal(t, status, []v1alpha1.RequirementStatus(nil))
}
})
}
}

0 comments on commit 190fc72

Please sign in to comment.