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 <tshort@redhat.com>
  • Loading branch information
tmshort committed Feb 6, 2024
1 parent 0381644 commit b7da141
Show file tree
Hide file tree
Showing 26 changed files with 4,100 additions and 729 deletions.
31 changes: 31 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,33 @@ 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) GetGeneration() int64 {
return r.ObjectMeta.GetGeneration()
}

func (r *ClusterExtension) GetConditions() *[]metav1.Condition {
return &r.Status.Conditions
}

func (r *ClusterExtension) SetInstalledBundleResource(s string) {
r.Status.InstalledBundleResource = s
}

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

func (r *ClusterExtension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
return r.Spec.UpgradeConstraintPolicy
}
65 changes: 44 additions & 21 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,12 +44,20 @@ 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"`

//+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"`
}

// TODO: Implement ExtensionSourceDirect containing a URL or other reference mechanism
Expand All @@ -66,31 +76,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 he 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 Down Expand Up @@ -131,3 +127,30 @@ type ExtensionList struct {
func init() {
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
}

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

func (r *Extension) GetGeneration() int64 {
return r.ObjectMeta.GetGeneration()
}

func (r *Extension) GetConditions() *[]metav1.Condition {
return &r.Status.Conditions
}

func (r *Extension) SetInstalledBundleResource(s string) {
r.Status.InstalledBundleResource = s
}

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 ""
}
6 changes: 4 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ func main() {
os.Exit(1)
}
if err = (&controllers.ExtensionReconciler{
Client: cl,
Scheme: mgr.GetScheme(),
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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/resolutioncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/controllers"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
Expand Down Expand Up @@ -162,7 +163,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
if err := cl.List(ctx, &bundleDeploymentList); err != nil {
return err
}
variables, err := controllers.GenerateVariables(allBundles, clusterExtensionList.Items, bundleDeploymentList.Items)
variables, err := controllers.GenerateVariables(allBundles, internal.ClusterExtensionArrayToInterface(clusterExtensionList.Items), bundleDeploymentList.Items)
if err != nil {
return err
}
Expand Down
38 changes: 20 additions & 18 deletions config/crd/bases/olm.operatorframework.io_extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,61 +34,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 he 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
29 changes: 29 additions & 0 deletions internal/controllers/bundle_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

"github.com/operator-framework/operator-controller/internal/catalogmetadata"
)

// 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)
}
Loading

0 comments on commit b7da141

Please sign in to comment.