Skip to content

Commit

Permalink
WIP: add new minimum version field for kube
Browse files Browse the repository at this point in the history
Check new CSV field against server version reported from discovery and
fail requirement check if version is earlier than necessary.
  • Loading branch information
Jeff Peeler committed Jan 9, 2019
1 parent 5a4031b commit 22b214d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type ClusterServiceVersionSpec struct {
CustomResourceDefinitions CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
APIServiceDefinitions APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
NativeAPIs []metav1.GroupVersionKind `json:"nativeAPIs,omitempty"`
MinKubeVersion string `json:"minKubeVersion,omitempty"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Expand Down Expand Up @@ -472,3 +473,4 @@ func (csv ClusterServiceVersion) GetOwnedAPIServiceDescriptions() []APIServiceDe

return descs
}

50 changes: 48 additions & 2 deletions pkg/controller/operators/olm/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package olm
import (
"encoding/json"
"fmt"
"strconv"

"github.com/sirupsen/logrus"

Expand All @@ -11,11 +12,13 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/coreos/go-semver/semver"
)

func (a *Operator) requirementStatus(strategyDetailsDeployment *install.StrategyDetailsDeployment, crdDescs []v1alpha1.CRDDescription,
ownedAPIServiceDescs []v1alpha1.APIServiceDescription, requiredAPIServiceDescs []v1alpha1.APIServiceDescription,
requiredNativeAPIs []metav1.GroupVersionKind) (met bool, statuses []v1alpha1.RequirementStatus) {
requiredNativeAPIs []metav1.GroupVersionKind,
minKubeVersion string) (met bool, statuses []v1alpha1.RequirementStatus) {
met = true

// Check for CRDs
Expand Down Expand Up @@ -177,6 +180,49 @@ func (a *Operator) requirementStatus(strategyDetailsDeployment *install.Strategy
}
}

status := v1alpha1.RequirementStatus{
Group: "apiextensions.k8s.io",
Version: "v1beta1",
Kind: "CustomResourceDefinition",
// TODO: refactor?
Name: "TODO: csv name, needs refactoring to get name",
}

serverVersionInfo, err := a.client.Discovery().ServerVersion()
if err != nil {
// TODO: this status may be wrong
status.Status = v1alpha1.RequirementStatusReasonPresentNotSatisfied
status.Message = "Server version discovery error"
met = false
statuses = append(statuses, status)
}

// copy necessary fields into comparable for semver
majorInt, err := strconv.ParseInt(serverVersionInfo.Major, 10, 64)
minorInt, err := strconv.ParseInt(serverVersionInfo.Minor, 10, 64)

serverVersionComparable := semver.Version{
Major: majorInt,
Minor: minorInt,
}

csvVersionInfo, err := semver.NewVersion(minKubeVersion)
if err != nil {
// TODO: this status may be wrong
status.Status = v1alpha1.RequirementStatusReasonPresentNotSatisfied
status.Message = "CSV version parsing error"
met = false
statuses = append(statuses, status)
}

if csvVersionInfo.Compare(serverVersionComparable) < 0 {
// TODO: this status may be wrong
status.Status = v1alpha1.RequirementStatusReasonPresentNotSatisfied
status.Message = "CSV version requirement not met"
met = false
statuses = append(statuses, status)
}

return
}

Expand Down Expand Up @@ -292,7 +338,7 @@ func (a *Operator) requirementAndPermissionStatus(csv *v1alpha1.ClusterServiceVe
return false, nil, fmt.Errorf("could not cast install strategy as type %T", strategyDetailsDeployment)
}

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

rbacLister := a.lister.RbacV1()
roleLister := rbacLister.RoleLister()
Expand Down

0 comments on commit 22b214d

Please sign in to comment.