Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Initial support for Extension #598

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ resources:
kind: ClusterExtension
path: github.com/operator-framework/operator-controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: operatorframework.io
group: olm
kind: Extension
path: github.com/operator-framework/operator-controller/api/v1alpha1
version: v1alpha1
version: "3"
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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add UpgradeConstraintPolicy here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed yet, we have no processing for it in Extension

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking just in terms of symmetry with what you'd get from Extension.GetPackageSpec().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider removing GetPackageSpec and ExtensionInterface in general? It looks like all the functions right now receive concrete types. Someday, and that day may never come, we will add an interface. But until that day, we should be fine without it.

return p
}

func (r *ClusterExtension) GetUID() types.UID {
return r.ObjectMeta.GetUID()
}
Comment on lines +173 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do that? ObjectMeta is embedded and I believe GetUID() should be available without overriding. Or am I missing something?


func (r *ClusterExtension) GetUpgradeConstraintPolicy() UpgradeConstraintPolicy {
return r.Spec.UpgradeConstraintPolicy
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this since UpgradeConstraintPolicy is now part of the package struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interface function is not being used, so I'm removing it

141 changes: 141 additions & 0 deletions api/v1alpha1/extension_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
Copyright 2024.

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 v1alpha1

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

type ExtensionManagedState string

const (
// Peform reconcilliation of this Extension
ManagedStateActive ExtensionManagedState = "Active"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be necessary to add a new print column to show the state when doing kubectl get?

// Pause reconcilliation of this Extension
ManagedStatePaused ExtensionManagedState = "Paused"
)

type ExtensionSourcePackage struct {
//+kubebuilder:validation:MaxLength:=48
everettraven marked this conversation as resolved.
Show resolved Hide resolved
//+kubebuilder:validation:Pattern:=^[a-z0-9]+(-[a-z0-9]+)*$
// name specifies the name of the name of the package
Name string `json:"name"`
tmshort marked this conversation as resolved.
Show resolved Hide resolved

//+kubebuilder:validation:MaxLength:=64
//+kubebuilder:validation: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*)*$`
//+kubebuilder:Optional
// 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
//
// 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 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"`
}

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

// ExtensionSpec defines the desired state of Extension
type ExtensionSpec struct {
//+kubebuilder:validation:Enum:=Active;Paused
//+kubebuilder:default:=Active
//+kubebuilder:Optional
//
// 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:=253
//+kubebuilder:validation:Pattern:=^[a-z0-9]+([\.-][a-z0-9]+)*$
//
// 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"`
varshaprasad96 marked this conversation as resolved.
Show resolved Hide resolved

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

// ExtensionStatus defines the observed state of Extension
type ExtensionStatus struct {
// +optional
InstalledBundleResource string `json:"installedBundleResource,omitempty"`
// +optional
ResolvedBundleResource string `json:"resolvedBundleResource,omitempty"`

// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
}

//+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 {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ExtensionSpec `json:"spec,omitempty"`
Status ExtensionStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ExtensionList contains a list of Extension
type ExtensionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Extension `json:"items"`
}

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 ""
}
132 changes: 132 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 11 additions & 0 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
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)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the implications with not even adding a reconciler for the Extension API to the controller manager is that if this feature gate is disabled, creating an Extension resource will silently do nothing. From a UX perspective I think it would make sense to still add the reconciler but when the feature gate is disabled we simply add a status condition that states something along the lines of "Reconciliation skipped. feature gate for the Extension API is disabled. The Extension API is an alpha feature that is still in development. To enable reconciliation use the flag --feature-gates=EnableExtensionApi=true".

Doing this would at least signal to an end user that it is currently in a "do nothing" state and how to enable it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I'm also not sure of any API versioning constraints that come with adding a status condition for this. Definitely something to think about regarding the pros/cons

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm a bit torn. on where to put the feature gate.

Copy link
Member

@varshaprasad96 varshaprasad96 Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ideal scenario would be to not have the Extension CRD applied if the feature gate is disabled - but I don't think that's something which is possible here, since the CRDs are applied before the controller pod is created. Instead of setting up the reconciler by default and adding the overhead of watching Extension resources, what do you all think about adding a log/warning during startup, mentioning the value of the feature gate flag, and explicitly stating something on the lines of - "feature gate flag for ExtensionAPI set to false, no action will be taken by operator controller if Extension object is created". That should to some extent satisfy the UI difficulties without having us to take more effort on it for now and at the same time not be a surprise for the user that nothing is happening when Extension is created?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varshaprasad96 I think that assumes a user who might create the Extension resource would have an understanding to go and look at the logs of the operator-controller pod and explicitly find that singular log message.

Throwing a message on the status is more immediately visible IMO and to me doesn't feel like a bunch of overhead. I'm mainly approaching this from what I would want as a user and I would much prefer seeing a status be set than having to find the pod that is running the controller manager, get the logs, and search the logs for any indication as to why nothing happened

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@everettraven has a point, if your extension isn't running, you're going to look at your extension first, and not necessarily a pod to which you don't have log access to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on why this suggestion:

I think that assumes a user who might create the Extension resource would have an understanding to go and look at the logs of the operator-controller pod and explicitly find that singular log message.

I would expect that users who create Extension resources have the understanding of troubleshooting at this stage, which includes checking logs when something doesn't work as expected - this is particularly considering the fact that afaik there is no one trying to use v1 in production in near future, at least till we make kapp-ctrl switch -scheduled soon.

That being said, I understand and completely agree that having just a log line - that too in an o-c pod that the user trying to install the package, ideally should not concern with - is not the perfect UX. This is to avoid - both the overhead of having an additional reconciler watch extension and other relevant resources on cluster which is not necessary, and us spending time on an API field that could turn out to be temporary in very near future. On a quick search upstream found an example of one of the optional controllers enabled only when the feature gate is present.

//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Loading
Loading