-
Notifications
You must be signed in to change notification settings - Fork 75
OCPCLOUD-3318: Integrate CompatibilityRequirements into the CCAPIO Insaller (WIP) #604
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
Changes from 6 commits
afcc0e6
b653d3b
79f9a43
2de3d3a
46628de
6619812
c891272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,13 +89,7 @@ func (r *RevisionController) Reconcile(ctx context.Context, _ ctrl.Request) (ctr | |
| } | ||
|
|
||
| func (r *RevisionController) reconcile(ctx context.Context, log logr.Logger) operatorstatus.ReconcileResult { | ||
| // Generate a desired revision from the current state | ||
| desiredRevision, result := r.generateDesiredRevision(ctx) | ||
| if result != nil { | ||
| return *result | ||
| } | ||
|
|
||
| // Get ClusterAPI singleton | ||
| // Get ClusterAPI singleton first — generateDesiredRevision needs spec fields. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is such a clanker comment 😅
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup - welcome to the future .. |
||
| clusterAPI := &operatorv1alpha1.ClusterAPI{} | ||
| if err := r.Get(ctx, client.ObjectKey{Name: clusterAPIName}, clusterAPI); err != nil { | ||
| if apierrors.IsNotFound(err) { | ||
|
|
@@ -105,6 +99,16 @@ func (r *RevisionController) reconcile(ctx context.Context, log logr.Logger) ope | |
| return opresult.Error(fmt.Errorf("fetching ClusterAPI: %w", err)) | ||
| } | ||
|
|
||
| var unmanagedCRDs []string | ||
| if clusterAPI.Spec != nil { | ||
| unmanagedCRDs = clusterAPI.Spec.UnmanagedCustomResourceDefinitions | ||
| } | ||
|
|
||
| desiredRevision, result := r.generateDesiredRevision(ctx, unmanagedCRDs) | ||
| if result != nil { | ||
| return *result | ||
| } | ||
|
|
||
| // Create a reverse sorted, merged list of revisions. It will prepend the | ||
| // new revision if necessary. Note that the latest revision is always | ||
| // first, and there is guaranteed to be at least one revision. | ||
|
|
@@ -134,7 +138,7 @@ func (r *RevisionController) reconcile(ctx context.Context, log logr.Logger) ope | |
| return opresult.Success() | ||
| } | ||
|
|
||
| func (r *RevisionController) generateDesiredRevision(ctx context.Context) (revisiongenerator.RenderedRevision, *operatorstatus.ReconcileResult) { | ||
| func (r *RevisionController) generateDesiredRevision(ctx context.Context, unmanagedCRDs []string) (revisiongenerator.RenderedRevision, *operatorstatus.ReconcileResult) { | ||
| infra := &configv1.Infrastructure{} | ||
| if err := r.Get(ctx, client.ObjectKey{Name: infrastructureName}, infra); err != nil { | ||
| return nil, opresult.ErrorP(fmt.Errorf("fetching infrastructure: %w", err)) | ||
|
|
@@ -147,7 +151,10 @@ func (r *RevisionController) generateDesiredRevision(ctx context.Context) (revis | |
| // Build ordered component list from provider metadata | ||
| providerComponents := r.buildComponentList(infra.Status.PlatformStatus.Type) | ||
|
|
||
| revision, err := revisiongenerator.NewRenderedRevision(providerComponents, revisiongenerator.WithManifestSubstitutions(r.manifestSubstitutions)) | ||
| revision, err := revisiongenerator.NewRenderedRevision(providerComponents, | ||
| revisiongenerator.WithManifestSubstitutions(r.manifestSubstitutions), | ||
| revisiongenerator.WithUnmanagedCRDs(unmanagedCRDs), | ||
| ) | ||
| if err != nil { | ||
| return nil, opresult.ErrorP(fmt.Errorf("error creating rendered revision: %w", err)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* | ||
| Copyright 2026 Red Hat, Inc. | ||
|
|
||
| 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 revisiongenerator | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| apiextensionsv1alpha1 "github.com/openshift/api/apiextensions/v1alpha1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| k8syaml "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| const ( | ||
| compatibilityRequirementNamePrefix = "ccapio-" | ||
| capiNamespace = "openshift-cluster-api" | ||
| ) | ||
|
|
||
| // buildCompatibilityRequirement constructs a CompatibilityRequirement for the | ||
| // given CRD and returns it as an unstructured object for inclusion in a | ||
| // renderedComponent. | ||
| func buildCompatibilityRequirement(crd unstructured.Unstructured) (unstructured.Unstructured, error) { | ||
| crdYAML, err := k8syaml.Marshal(crd.Object) | ||
| if err != nil { | ||
| return unstructured.Unstructured{}, fmt.Errorf("marshalling CRD %s to YAML: %w", crd.GetName(), err) | ||
| } | ||
|
|
||
| cr := &apiextensionsv1alpha1.CompatibilityRequirement{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| APIVersion: apiextensionsv1alpha1.GroupVersion.String(), | ||
| Kind: "CompatibilityRequirement", | ||
| }, | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: compatibilityRequirementNamePrefix + crd.GetName(), | ||
| }, | ||
|
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against invalid Line 49 can generate a Suggested fix+const maxK8sNameLen = 253
+
+func compatibilityRequirementName(crdName string) string {
+ name := compatibilityRequirementNamePrefix + crdName
+ if len(name) <= maxK8sNameLen {
+ return name
+ }
+
+ // keep deterministic name while preserving uniqueness
+ sum := sha256.Sum256([]byte(crdName))
+ suffix := "-" + hex.EncodeToString(sum[:8])
+ keep := maxK8sNameLen - len(suffix)
+ return name[:keep] + suffix
+}
+
func buildCompatibilityRequirement(crd unstructured.Unstructured) (unstructured.Unstructured, error) {
@@
ObjectMeta: metav1.ObjectMeta{
- Name: compatibilityRequirementNamePrefix + crd.GetName(),
+ Name: compatibilityRequirementName(crd.GetName()),
},🤖 Prompt for AI Agents |
||
| Spec: apiextensionsv1alpha1.CompatibilityRequirementSpec{ | ||
| CompatibilitySchema: apiextensionsv1alpha1.CompatibilitySchema{ | ||
| CustomResourceDefinition: apiextensionsv1alpha1.CRDData{ | ||
| Type: apiextensionsv1alpha1.CRDDataTypeYAML, | ||
| Data: string(crdYAML), | ||
| }, | ||
| }, | ||
| CustomResourceDefinitionSchemaValidation: apiextensionsv1alpha1.CustomResourceDefinitionSchemaValidation{ | ||
| Action: apiextensionsv1alpha1.CRDAdmitActionDeny, | ||
| }, | ||
| ObjectSchemaValidation: apiextensionsv1alpha1.ObjectSchemaValidation{ | ||
| Action: apiextensionsv1alpha1.CRDAdmitActionDeny, | ||
| NamespaceSelector: metav1.LabelSelector{ | ||
| MatchLabels: map[string]string{ | ||
| "kubernetes.io/metadata.name": capiNamespace, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| data, err := runtime.DefaultUnstructuredConverter.ToUnstructured(cr) | ||
| if err != nil { | ||
| return unstructured.Unstructured{}, fmt.Errorf("converting CompatibilityRequirement to unstructured: %w", err) | ||
| } | ||
|
|
||
| return unstructured.Unstructured{Object: data}, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.