Skip to content

Commit

Permalink
add 'spec.nativeAPIs' field to CSV and check that native APIs exist b…
Browse files Browse the repository at this point in the history
…efore install
  • Loading branch information
alecmerdler committed Oct 29, 2018
1 parent d7ee481 commit d927772
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
13 changes: 11 additions & 2 deletions pkg/api/apis/operators/v1alpha1/clusterserviceversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,23 @@ type APIServiceDefinitions struct {
Required []APIServiceDescription `json:"required,omitempty"`
}

// ClusterServiceVersionSpec declarations tell the OLM how to install an operator
// that can manage apps for given version and AppType.
// NativeAPI describes the GVK of a Kubernetes resource that is required by an
// Operator, but must be provided by the underlying cluster and not an extension.
type NativeAPI struct {
Group string `json:"group"`
Version string `json:"version"`
Kind string `json:"kind"`
}

// ClusterServiceVersionSpec declarations tell OLM how to install an operator
// that can manage apps for a given version.
type ClusterServiceVersionSpec struct {
InstallStrategy NamedInstallStrategy `json:"install"`
Version semver.Version `json:"version,omitempty"`
Maturity string `json:"maturity,omitempty"`
CustomResourceDefinitions CustomResourceDefinitions `json:"customresourcedefinitions,omitempty"`
APIServiceDefinitions APIServiceDefinitions `json:"apiservicedefinitions,omitempty"`
NativeAPIs []NativeAPI `json:"nativeAPIs,omitempty"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
Keywords []string `json:"keywords,omitempty"`
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/apis/operators/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 24 additions & 2 deletions pkg/controller/operators/olm/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

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

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

for _, r := range requiredNativeAPIs {
name := fmt.Sprintf("%s.%s", r.Version, r.Group)
status := v1alpha1.RequirementStatus{
Group: r.Group,
Version: r.Version,
Kind: r.Kind,
Name: name,
}

if err := a.isGVKRegistered(r.Group, r.Version, r.Kind); err != nil {
status.Status = v1alpha1.RequirementStatusReasonNotPresent
met = false
statuses = append(statuses, status)
continue
} else {
status.Status = v1alpha1.RequirementStatusReasonPresent
statuses = append(statuses, status)
continue
}
}

return
}

Expand Down Expand Up @@ -238,7 +260,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())
reqMet, reqStatuses := a.requirementStatus(strategyDetailsDeployment, csv.GetAllCRDDescriptions(), csv.GetOwnedAPIServiceDescriptions(), csv.GetRequiredAPIServiceDescriptions(), csv.Spec.NativeAPIs)

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

0 comments on commit d927772

Please sign in to comment.