Skip to content

Commit

Permalink
✨ Plumb the Extension API
Browse files Browse the repository at this point in the history
Copies ClustersExtension functionality

`ServiceAccountName` doesn't do anything yet.

Signed-off-by: Todd Short <[email protected]>
  • Loading branch information
tmshort committed Feb 13, 2024
1 parent 5b8f9d2 commit a5c894b
Show file tree
Hide file tree
Showing 15 changed files with 668 additions and 153 deletions.
19 changes: 19 additions & 0 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/operator-framework/operator-controller/internal/conditionsets"
)
Expand Down Expand Up @@ -158,3 +159,21 @@ type ClusterExtensionList struct {
func init() {
SchemeBuilder.Register(&ClusterExtension{}, &ClusterExtensionList{})
}

func (r *ClusterExtension) GetPackageSpec() *ExtensionSourcePackage {
p := &ExtensionSourcePackage{}

p.Channel = r.Spec.Channel
p.Name = r.Spec.PackageName
p.Version = r.Spec.Version

return p
}

func (r *ClusterExtension) GetUID() types.UID {
return r.ObjectMeta.GetUID()
}

func (r *ClusterExtension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
return r.Spec.UpgradeConstraintPolicy
}
60 changes: 34 additions & 26 deletions api/v1alpha1/extension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type ExtensionManagedState string

const (
// Pause resolution of this Extension
// Peform reconcilliation of this Extension
ManagedStateActive ExtensionManagedState = "Active"
// Peform resolution of this Extension
// Pause reconcilliation of this Extension
ManagedStatePaused ExtensionManagedState = "Paused"
)

type ExtensionSourcePackage struct {
//+kubebuilder:validation:MaxLength:=48
//+kubebuilder:validation:Pattern:=^[a-z0-9]+(-[a-z0-9]+)*$
// name specifies the name of the name of the package
Name string `json:"name"`

//+kubebuilder:validation:MaxLength:=64
Expand All @@ -42,22 +44,26 @@ type ExtensionSourcePackage struct {
// Examples: 1.2.3, 1.0.0-alpha, 1.0.0-rc.1
//
// For more information on semver, please see https://semver.org/
// version constraint definition
Version string `json:"version,omitempty"`

//+kubebuilder:validation:MaxLength:=48
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
// Channel constraint definition
// channel constraint definition
Channel string `json:"channel,omitempty"`
}

// TODO: Implement ExtensionSourceDirect containing a URL or other reference mechanism
//+kubebuilder:validation:Enum:=Enforce;Ignore
//+kubebuilder:default:=Enforce
//+kubebuilder:Optional
//
// upgradeConstraintPolicy Defines the policy for how to handle upgrade constraints
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
}

// ExtensionSource defines the source for this Extension, right now, only a package is supported.
type ExtensionSource struct {
// A source package defined by a name, version and/or channel
Package *ExtensionSourcePackage `json:"package,omitempty"`

// A direct package defined by a URL
// TODO: Direct *ExtensionSourceDirect `json:"direct,omitempty"`
}

// ExtensionSpec defines the desired state of Extension
Expand All @@ -66,31 +72,17 @@ type ExtensionSpec struct {
//+kubebuilder:default:=Active
//+kubebuilder:Optional
//
// Pause reconciliation on this Extension
// managed controls the management state of the extension. "Active" means this extension will be reconciled and "Paused" means this extension will be ignored.
Managed ExtensionManagedState `json:"managed,omitempty"`

//+kubebuilder:validation:MaxLength:=64
//+kubebuilder:validation:MaxLength:=253
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
//
// ServiceAccount name used to install this extension
// serviceAccountName is the name of a service account in the Extension's namespace that will be used to manage the installation and lifecycle of the extension.
ServiceAccountName string `json:"serviceAccountName"`

//+kubebuilder:validation:MaxLength:=64
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
//+kubebuilder:Optional
//
// Location of installation TBD??
DefaultNamespace string `json:"defaultNamespace,omitempty"`

// Source of Extension to be installed
// source of Extension to be installed
Source ExtensionSource `json:"source"`

//+kubebuilder:validation:Enum:=Enforce;Ignore
//+kubebuilder:default:=Enforce
//+kubebuilder:Optional
//
// Defines the policy for how to handle upgrade constraints
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
}

// ExtensionStatus defines the observed state of Extension
Expand All @@ -109,6 +101,7 @@ type ExtensionStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Managed",type=string,JSONPath=`.spec.managed`,description="The current reconciliation state of this extension"

// Extension is the Schema for the extensions API
type Extension struct {
Expand All @@ -131,3 +124,18 @@ type ExtensionList struct {
func init() {
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
}

func (r *Extension) GetPackageSpec() *ExtensionSourcePackage {
return r.Spec.Source.Package.DeepCopy()
}

func (r *Extension) GetUID() types.UID {
return r.ObjectMeta.GetUID()
}

func (r *Extension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
if r.Spec.Source.Package != nil {
return r.Spec.Source.Package.UpgradeConstraintPolicy
}
return ""
}
16 changes: 10 additions & 6 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
os.Exit(1)
}
if err = (&controllers.ExtensionReconciler{
Client: cl,
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Extension")
os.Exit(1)
if features.OperatorControllerFeatureGate.Enabled(features.EnableExtensionApi) {
if err = (&controllers.ExtensionReconciler{
Client: cl,
BundleProvider: catalogClient,
Scheme: mgr.GetScheme(),
Resolver: resolver,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Extension")
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder

Expand Down
45 changes: 26 additions & 19 deletions config/crd/bases/olm.operatorframework.io_extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ spec:
singular: extension
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: The current reconciliation state of this extension
jsonPath: .spec.managed
name: Managed
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Extension is the Schema for the extensions API
Expand All @@ -34,61 +39,63 @@ spec:
spec:
description: ExtensionSpec defines the desired state of Extension
properties:
defaultNamespace:
description: Location of installation TBD??
maxLength: 64
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
type: string
managed:
default: Active
description: Pause reconciliation on this Extension
description: managed controls the management state of the extension.
"Active" means this extension will be reconciled and "Paused" means
this extension will be ignored.
enum:
- Active
- Paused
type: string
serviceAccountName:
description: ServiceAccount name used to install this extension
maxLength: 64
description: serviceAccountName is the name of a service account in
the Extension's namespace that will be used to manage the installation
and lifecycle of the extension.
maxLength: 253
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
type: string
source:
description: Source of Extension to be installed
description: source of Extension to be installed
properties:
package:
description: A source package defined by a name, version and/or
channel
properties:
channel:
description: Channel constraint definition
description: channel constraint definition
maxLength: 48
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
type: string
name:
description: name specifies the name of the name of the package
maxLength: 48
pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
type: string
upgradeConstraintPolicy:
default: Enforce
description: upgradeConstraintPolicy Defines the policy for
how to handle upgrade constraints
enum:
- Enforce
- Ignore
type: string
version:
description: "Version is an optional semver constraint on
the package version. If not specified, the latest version
available of the package will be installed. If specified,
the specific version of the package will be installed so
long as it is available in any of the content sources available.
Examples: 1.2.3, 1.0.0-alpha, 1.0.0-rc.1 \n For more information
on semver, please see https://semver.org/"
on semver, please see https://semver.org/ version constraint
definition"
maxLength: 64
pattern: ^(\s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|[x|X|\*])(\.(0|[1-9]\d*|x|X|\*]))?(\.(0|[1-9]\d*|x|X|\*))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)((?:\s+|,\s*|\s*\|\|\s*)(=||!=|>|<|>=|=>|<=|=<|~|~>|\^)\s*(v?(0|[1-9]\d*|x|X|\*])(\.(0|[1-9]\d*|x|X|\*))?(\.(0|[1-9]\d*|x|X|\*]))?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?)\s*)*$
type: string
required:
- name
type: object
type: object
upgradeConstraintPolicy:
default: Enforce
description: Defines the policy for how to handle upgrade constraints
enum:
- Enforce
- Ignore
type: string
required:
- serviceAccountName
- source
Expand Down
1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# It should be run by config/default
resources:
- bases/olm.operatorframework.io_clusterextensions.yaml
- bases/olm.operatorframework.io_extensions.yaml

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
Expand Down
91 changes: 0 additions & 91 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ import (
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
)

// BundleProvider provides the way to retrieve a list of Bundles from a source,
// generally from a catalog client of some kind.
type BundleProvider interface {
Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
}

// ClusterExtensionReconciler reconciles a ClusterExtension object
type ClusterExtensionReconciler struct {
client.Client
Expand Down Expand Up @@ -492,91 +486,6 @@ func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {
}
}

// setResolvedStatusConditionSuccess sets the resolved status condition to success.
func setResolvedStatusConditionSuccess(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeResolved,
Status: metav1.ConditionTrue,
Reason: ocv1alpha1.ReasonSuccess,
Message: message,
ObservedGeneration: generation,
})
}

// setResolvedStatusConditionFailed sets the resolved status condition to failed.
func setResolvedStatusConditionFailed(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeResolved,
Status: metav1.ConditionFalse,
Reason: ocv1alpha1.ReasonResolutionFailed,
Message: message,
ObservedGeneration: generation,
})
}

// setResolvedStatusConditionUnknown sets the resolved status condition to unknown.
func setResolvedStatusConditionUnknown(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeResolved,
Status: metav1.ConditionUnknown,
Reason: ocv1alpha1.ReasonResolutionUnknown,
Message: message,
ObservedGeneration: generation,
})
}

// setInstalledStatusConditionSuccess sets the installed status condition to success.
func setInstalledStatusConditionSuccess(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeInstalled,
Status: metav1.ConditionTrue,
Reason: ocv1alpha1.ReasonSuccess,
Message: message,
ObservedGeneration: generation,
})
}

// setInstalledStatusConditionFailed sets the installed status condition to failed.
func setInstalledStatusConditionFailed(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeInstalled,
Status: metav1.ConditionFalse,
Reason: ocv1alpha1.ReasonInstallationFailed,
Message: message,
ObservedGeneration: generation,
})
}

// setInstalledStatusConditionUnknown sets the installed status condition to unknown.
func setInstalledStatusConditionUnknown(conditions *[]metav1.Condition, message string, generation int64) {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: ocv1alpha1.TypeInstalled,
Status: metav1.ConditionUnknown,
Reason: ocv1alpha1.ReasonInstallationStatusUnknown,
Message: message,
ObservedGeneration: generation,
})
}

func setDeprecationStatusesUnknown(conditions *[]metav1.Condition, message string, generation int64) {
conditionTypes := []string{
ocv1alpha1.TypeDeprecated,
ocv1alpha1.TypePackageDeprecated,
ocv1alpha1.TypeChannelDeprecated,
ocv1alpha1.TypeBundleDeprecated,
}

for _, conditionType := range conditionTypes {
apimeta.SetStatusCondition(conditions, metav1.Condition{
Type: conditionType,
Reason: ocv1alpha1.ReasonDeprecated,
Status: metav1.ConditionUnknown,
Message: message,
ObservedGeneration: generation,
})
}
}

// Generate reconcile requests for all cluster extensions affected by a catalog change
func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) handler.MapFunc {
return func(ctx context.Context, _ client.Object) []reconcile.Request {
Expand Down
Loading

0 comments on commit a5c894b

Please sign in to comment.