Skip to content

Commit e3da267

Browse files
committed
✨ Plumb the Extension API
Copies ClustersExtension functionality `ServiceAccountName` doesn't do anything yet. Signed-off-by: Todd Short <[email protected]>
1 parent 0381644 commit e3da267

27 files changed

+4126
-718
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/types"
2122

2223
"github.com/operator-framework/operator-controller/internal/conditionsets"
2324
)
@@ -158,3 +159,33 @@ type ClusterExtensionList struct {
158159
func init() {
159160
SchemeBuilder.Register(&ClusterExtension{}, &ClusterExtensionList{})
160161
}
162+
163+
func (r *ClusterExtension) GetPackageSpec() *ExtensionSourcePackage {
164+
p := &ExtensionSourcePackage{}
165+
166+
p.Channel = r.Spec.Channel
167+
p.Name = r.Spec.PackageName
168+
p.Version = r.Spec.Version
169+
170+
return p
171+
}
172+
173+
func (r *ClusterExtension) GetGeneration() int64 {
174+
return r.ObjectMeta.GetGeneration()
175+
}
176+
177+
func (r *ClusterExtension) GetConditions() *[]metav1.Condition {
178+
return &r.Status.Conditions
179+
}
180+
181+
func (r *ClusterExtension) SetInstalledBundleResource(s string) {
182+
r.Status.InstalledBundleResource = s
183+
}
184+
185+
func (r *ClusterExtension) GetUID() types.UID {
186+
return r.ObjectMeta.GetUID()
187+
}
188+
189+
func (r *ClusterExtension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
190+
return r.Spec.UpgradeConstraintPolicy
191+
}

api/v1alpha1/extension_types.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/types"
2122
)
2223

2324
type ExtensionManagedState string
2425

2526
const (
26-
// Pause resolution of this Extension
27+
// Peform reconcilliation of this Extension
2728
ManagedStateActive ExtensionManagedState = "Active"
28-
// Peform resolution of this Extension
29+
// Pause reconcilliation of this Extension
2930
ManagedStatePaused ExtensionManagedState = "Paused"
3031
)
3132

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

3739
//+kubebuilder:validation:MaxLength:=64
@@ -42,12 +44,20 @@ type ExtensionSourcePackage struct {
4244
// Examples: 1.2.3, 1.0.0-alpha, 1.0.0-rc.1
4345
//
4446
// For more information on semver, please see https://semver.org/
47+
// version constraint definition
4548
Version string `json:"version,omitempty"`
4649

4750
//+kubebuilder:validation:MaxLength:=48
4851
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
49-
// Channel constraint definition
52+
// channel constraint definition
5053
Channel string `json:"channel,omitempty"`
54+
55+
//+kubebuilder:validation:Enum:=Enforce;Ignore
56+
//+kubebuilder:default:=Enforce
57+
//+kubebuilder:Optional
58+
//
59+
// upgradeConstraintPolicy Defines the policy for how to handle upgrade constraints
60+
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
5161
}
5262

5363
// TODO: Implement ExtensionSourceDirect containing a URL or other reference mechanism
@@ -66,31 +76,30 @@ type ExtensionSpec struct {
6676
//+kubebuilder:default:=Active
6777
//+kubebuilder:Optional
6878
//
69-
// Pause reconciliation on this Extension
79+
// managed controls the management state of the extension. "Active" means this extension will be reconciled and "Paused" means this extension will be ignored.
7080
Managed ExtensionManagedState `json:"managed,omitempty"`
7181

72-
//+kubebuilder:validation:MaxLength:=64
82+
//+kubebuilder:validation:MaxLength:=253
7383
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
7484
//
75-
// ServiceAccount name used to install this extension
85+
// 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.
7686
ServiceAccountName string `json:"serviceAccountName"`
7787

78-
//+kubebuilder:validation:MaxLength:=64
88+
//+kubebuilder:validation:MaxLength:=253
7989
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
8090
//+kubebuilder:Optional
8191
//
82-
// Location of installation TBD??
92+
// defaultNamespace is the location of installation if different than the resource namespace
8393
DefaultNamespace string `json:"defaultNamespace,omitempty"`
8494

85-
// Source of Extension to be installed
95+
// source of Extension to be installed
8696
Source ExtensionSource `json:"source"`
8797

88-
//+kubebuilder:validation:Enum:=Enforce;Ignore
89-
//+kubebuilder:default:=Enforce
9098
//+kubebuilder:Optional
9199
//
92-
// Defines the policy for how to handle upgrade constraints
93-
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
100+
// watchNamespaces indicates which namespaces the extension should watch.
101+
// This feature is currently supported only with RegistryV1 bundles.
102+
WatchNamespaces []string `json:"watchNamespaces,omitempty"`
94103
}
95104

96105
// ExtensionStatus defines the observed state of Extension
@@ -131,3 +140,30 @@ type ExtensionList struct {
131140
func init() {
132141
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
133142
}
143+
144+
func (r *Extension) GetPackageSpec() *ExtensionSourcePackage {
145+
return r.Spec.Source.Package.DeepCopy()
146+
}
147+
148+
func (r *Extension) GetGeneration() int64 {
149+
return r.ObjectMeta.GetGeneration()
150+
}
151+
152+
func (r *Extension) GetConditions() *[]metav1.Condition {
153+
return &r.Status.Conditions
154+
}
155+
156+
func (r *Extension) SetInstalledBundleResource(s string) {
157+
r.Status.InstalledBundleResource = s
158+
}
159+
160+
func (r *Extension) GetUID() types.UID {
161+
return r.ObjectMeta.GetUID()
162+
}
163+
164+
func (r *Extension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
165+
if r.Spec.Source.Package != nil {
166+
return r.Spec.Source.Package.UpgradeConstraintPolicy
167+
}
168+
return ""
169+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ func main() {
124124
os.Exit(1)
125125
}
126126
if err = (&controllers.ExtensionReconciler{
127-
Client: cl,
128-
Scheme: mgr.GetScheme(),
127+
Client: cl,
128+
BundleProvider: catalogClient,
129+
Scheme: mgr.GetScheme(),
130+
Resolver: resolver,
129131
}).SetupWithManager(mgr); err != nil {
130132
setupLog.Error(err, "unable to create controller", "controller", "Extension")
131133
os.Exit(1)

cmd/resolutioncli/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3636

3737
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
38+
"github.com/operator-framework/operator-controller/internal"
3839
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
3940
"github.com/operator-framework/operator-controller/internal/controllers"
4041
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
@@ -162,7 +163,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
162163
if err := cl.List(ctx, &bundleDeploymentList); err != nil {
163164
return err
164165
}
165-
variables, err := controllers.GenerateVariables(allBundles, clusterExtensionList.Items, bundleDeploymentList.Items)
166+
variables, err := controllers.GenerateVariables(allBundles, internal.ClusterExtensionArrayToInterface(clusterExtensionList.Items), bundleDeploymentList.Items)
166167
if err != nil {
167168
return err
168169
}

config/crd/bases/olm.operatorframework.io_extensions.yaml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,60 +35,75 @@ spec:
3535
description: ExtensionSpec defines the desired state of Extension
3636
properties:
3737
defaultNamespace:
38-
description: Location of installation TBD??
39-
maxLength: 64
38+
description: defaultNamespace is the location of installation if different
39+
than the resource namespace
40+
maxLength: 253
4041
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
4142
type: string
4243
managed:
4344
default: Active
44-
description: Pause reconciliation on this Extension
45+
description: managed controls the management state of the extension.
46+
"Active" means this extension will be reconciled and "Paused" means
47+
this extension will be ignored.
4548
enum:
4649
- Active
4750
- Paused
4851
type: string
4952
serviceAccountName:
50-
description: ServiceAccount name used to install this extension
51-
maxLength: 64
53+
description: serviceAccountName is he name of a service account in
54+
the Extension's namespace that will be used to manage the installation
55+
and lifecycle of the extension.
56+
maxLength: 253
5257
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
5358
type: string
5459
source:
55-
description: Source of Extension to be installed
60+
description: source of Extension to be installed
5661
properties:
5762
package:
5863
description: A source package defined by a name, version and/or
5964
channel
6065
properties:
6166
channel:
62-
description: Channel constraint definition
67+
description: channel constraint definition
6368
maxLength: 48
6469
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
6570
type: string
6671
name:
72+
description: name specifies the name of the name of the package
6773
maxLength: 48
6874
pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
6975
type: string
76+
upgradeConstraintPolicy:
77+
default: Enforce
78+
description: upgradeConstraintPolicy Defines the policy for
79+
how to handle upgrade constraints
80+
enum:
81+
- Enforce
82+
- Ignore
83+
type: string
7084
version:
7185
description: "Version is an optional semver constraint on
7286
the package version. If not specified, the latest version
7387
available of the package will be installed. If specified,
7488
the specific version of the package will be installed so
7589
long as it is available in any of the content sources available.
7690
Examples: 1.2.3, 1.0.0-alpha, 1.0.0-rc.1 \n For more information
77-
on semver, please see https://semver.org/"
91+
on semver, please see https://semver.org/ version constraint
92+
definition"
7893
maxLength: 64
7994
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*)*$
8095
type: string
8196
required:
8297
- name
8398
type: object
8499
type: object
85-
upgradeConstraintPolicy:
86-
default: Enforce
87-
description: Defines the policy for how to handle upgrade constraints
88-
enum:
89-
- Enforce
90-
- Ignore
91-
type: string
100+
watchNamespaces:
101+
description: watchNamespaces indicates which namespaces the extension
102+
should watch. This feature is currently supported only with RegistryV1
103+
bundles.
104+
items:
105+
type: string
106+
type: array
92107
required:
93108
- serviceAccountName
94109
- source

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# It should be run by config/default
44
resources:
55
- bases/olm.operatorframework.io_clusterextensions.yaml
6+
- bases/olm.operatorframework.io_extensions.yaml
67

78
# the following config is for teaching kustomize how to do kustomization for CRDs.
89
configurations:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
22+
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
23+
)
24+
25+
// BundleProvider provides the way to retrieve a list of Bundles from a source,
26+
// generally from a catalog client of some kind.
27+
type BundleProvider interface {
28+
Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
29+
}

0 commit comments

Comments
 (0)