Skip to content

Commit b7da141

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 b7da141

26 files changed

+4100
-729
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: 44 additions & 21 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,17 @@ 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
79-
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
80-
//+kubebuilder:Optional
81-
//
82-
// Location of installation TBD??
83-
DefaultNamespace string `json:"defaultNamespace,omitempty"`
84-
85-
// Source of Extension to be installed
88+
// source of Extension to be installed
8689
Source ExtensionSource `json:"source"`
87-
88-
//+kubebuilder:validation:Enum:=Enforce;Ignore
89-
//+kubebuilder:default:=Enforce
90-
//+kubebuilder:Optional
91-
//
92-
// Defines the policy for how to handle upgrade constraints
93-
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
9490
}
9591

9692
// ExtensionStatus defines the observed state of Extension
@@ -131,3 +127,30 @@ type ExtensionList struct {
131127
func init() {
132128
SchemeBuilder.Register(&Extension{}, &ExtensionList{})
133129
}
130+
131+
func (r *Extension) GetPackageSpec() *ExtensionSourcePackage {
132+
return r.Spec.Source.Package.DeepCopy()
133+
}
134+
135+
func (r *Extension) GetGeneration() int64 {
136+
return r.ObjectMeta.GetGeneration()
137+
}
138+
139+
func (r *Extension) GetConditions() *[]metav1.Condition {
140+
return &r.Status.Conditions
141+
}
142+
143+
func (r *Extension) SetInstalledBundleResource(s string) {
144+
r.Status.InstalledBundleResource = s
145+
}
146+
147+
func (r *Extension) GetUID() types.UID {
148+
return r.ObjectMeta.GetUID()
149+
}
150+
151+
func (r *Extension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
152+
if r.Spec.Source.Package != nil {
153+
return r.Spec.Source.Package.UpgradeConstraintPolicy
154+
}
155+
return ""
156+
}

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: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,63 @@ spec:
3434
spec:
3535
description: ExtensionSpec defines the desired state of Extension
3636
properties:
37-
defaultNamespace:
38-
description: Location of installation TBD??
39-
maxLength: 64
40-
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
41-
type: string
4237
managed:
4338
default: Active
44-
description: Pause reconciliation on this Extension
39+
description: managed controls the management state of the extension.
40+
"Active" means this extension will be reconciled and "Paused" means
41+
this extension will be ignored.
4542
enum:
4643
- Active
4744
- Paused
4845
type: string
4946
serviceAccountName:
50-
description: ServiceAccount name used to install this extension
51-
maxLength: 64
47+
description: serviceAccountName is he name of a service account in
48+
the Extension's namespace that will be used to manage the installation
49+
and lifecycle of the extension.
50+
maxLength: 253
5251
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
5352
type: string
5453
source:
55-
description: Source of Extension to be installed
54+
description: source of Extension to be installed
5655
properties:
5756
package:
5857
description: A source package defined by a name, version and/or
5958
channel
6059
properties:
6160
channel:
62-
description: Channel constraint definition
61+
description: channel constraint definition
6362
maxLength: 48
6463
pattern: ^[a-z0-9]+([\.-][a-z0-9]+)*$
6564
type: string
6665
name:
66+
description: name specifies the name of the name of the package
6767
maxLength: 48
6868
pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
6969
type: string
70+
upgradeConstraintPolicy:
71+
default: Enforce
72+
description: upgradeConstraintPolicy Defines the policy for
73+
how to handle upgrade constraints
74+
enum:
75+
- Enforce
76+
- Ignore
77+
type: string
7078
version:
7179
description: "Version is an optional semver constraint on
7280
the package version. If not specified, the latest version
7381
available of the package will be installed. If specified,
7482
the specific version of the package will be installed so
7583
long as it is available in any of the content sources available.
7684
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/"
85+
on semver, please see https://semver.org/ version constraint
86+
definition"
7887
maxLength: 64
7988
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*)*$
8089
type: string
8190
required:
8291
- name
8392
type: object
8493
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
9294
required:
9395
- serviceAccountName
9496
- 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)