-
Notifications
You must be signed in to change notification settings - Fork 75
test merge OCPCLOUD 3443 2664 #579
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
Closed
mdbooth
wants to merge
7
commits into
openshift:main
from
openshift-cloud-team:test-merge-OCPCLOUD-3443-2664
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0bb838c
operatorstatus: add WithUpdateOperatorVersion()
mdbooth 4f645e2
operatorstatus: convert Reason to iota type
mdbooth 9104384
Move version writing to revision controller
mdbooth 7189785
clusteroperator: aggregate sub-controller conditions
mdbooth ee8aae1
Bump envtest k8s version to 1.35.1
mdbooth 5ba262b
Installer is separate deployment managed by capi-operator
mdbooth c72a77f
Merge branch 'OCPCLOUD-3443' into test-merge-OCPCLOUD-3443-2664
mdbooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| // 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 main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| "k8s.io/utils/ptr" | ||
|
|
||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/cache" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1" | ||
|
|
||
| "github.com/openshift/cluster-capi-operator/pkg/commoncmdoptions" | ||
| "github.com/openshift/cluster-capi-operator/pkg/controllers" | ||
| "github.com/openshift/cluster-capi-operator/pkg/controllers/installer" | ||
| "github.com/openshift/cluster-capi-operator/pkg/controllers/revision" | ||
| "github.com/openshift/cluster-capi-operator/pkg/providerimages" | ||
| "github.com/openshift/cluster-capi-operator/pkg/util" | ||
| ) | ||
|
|
||
| var errPodIdentityNotSet = errors.New("POD_NAME and POD_NAMESPACE must be set") | ||
|
|
||
| const ( | ||
| managerName = "capi-installer" | ||
| ) | ||
|
|
||
| func initScheme(scheme *runtime.Scheme) { | ||
| utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
| utilruntime.Must(configv1.AddToScheme(scheme)) | ||
| utilruntime.Must(apiextensionsv1.AddToScheme(scheme)) | ||
| utilruntime.Must(appsv1.AddToScheme(scheme)) | ||
| utilruntime.Must(operatorv1alpha1.AddToScheme(scheme)) | ||
| } | ||
|
|
||
| func main() { | ||
| ctx, cancel := context.WithCancel(ctrl.SetupSignalHandler()) | ||
| cfg := ctrl.GetConfigOrDie() | ||
|
|
||
| scheme := runtime.NewScheme() | ||
| initScheme(scheme) | ||
|
|
||
| extraflags := flag.NewFlagSet("", flag.ContinueOnError) | ||
| providerImageDir := extraflags.String( | ||
| "provider-image-dir", | ||
| providerimages.ProviderImageMountBase, | ||
| "Directory containing provider image manifests. In dev mode, set to a local directory to skip pod spec reading.", | ||
| ) | ||
|
|
||
| log, operatorConfig, mgrOpts, initManager, err := commoncmdoptions.InitOperatorConfig(ctx, cfg, scheme, managerName, controllers.DefaultOperatorNamespace, extraflags) | ||
| if err != nil { | ||
| log.Error(err, "unable to initialize operator config") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| mgrOpts.Cache = cache.Options{ | ||
| DefaultNamespaces: map[string]cache.Config{ | ||
| *operatorConfig.CAPINamespace: {}, | ||
| *operatorConfig.OperatorNamespace: {}, | ||
| }, | ||
| SyncPeriod: ptr.To(10 * time.Minute), | ||
| } | ||
|
|
||
| mgr, err := initManager(ctx, cancel, mgrOpts) | ||
| if err != nil { | ||
| log.Error(err, "unable to initialize manager") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if err := setupControllers(ctx, mgr, operatorConfig, *providerImageDir); err != nil { | ||
| log.Error(err, "unable to setup controllers") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| log.Info("Starting " + managerName + " manager") | ||
|
|
||
| if err := mgr.Start(ctx); err != nil { | ||
| log.Error(err, "problem running manager") | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func setupControllers(ctx context.Context, mgr ctrl.Manager, operatorConfig commoncmdoptions.OperatorConfig, providerImageDir string) error { | ||
| allProviderProfiles, err := loadProviderImages(ctx, mgr, providerImageDir) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| currentReleaseRefs, err := loadCurrentReleaseImageRefs(ctx, mgr, *operatorConfig.OperatorNamespace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| currentReleaseProfiles := make([]providerimages.ProviderImageManifests, 0, len(allProviderProfiles)) | ||
| for _, profile := range allProviderProfiles { | ||
| if currentReleaseRefs.Has(profile.ImageRef) { | ||
| currentReleaseProfiles = append(currentReleaseProfiles, profile) | ||
| } | ||
| } | ||
|
|
||
| log := ctrl.LoggerFrom(ctx) | ||
| for _, profile := range allProviderProfiles { | ||
| log.Info("loaded provider profile", "name", profile.Name, "imageRef", profile.ImageRef, "profile", profile.Profile) | ||
| } | ||
|
|
||
| if err := (&revision.RevisionController{ | ||
| Client: mgr.GetClient(), | ||
| ProviderProfiles: currentReleaseProfiles, | ||
| ReleaseVersion: util.GetReleaseVersion(), | ||
| }).SetupWithManager(mgr, operatorConfig.TLSOptions); err != nil { | ||
| log.Error(err, "unable to create revision controller", "controller", "RevisionController") | ||
| return fmt.Errorf("unable to create revision controller: %w", err) | ||
| } | ||
|
|
||
| if err := installer.SetupWithManager(mgr, allProviderProfiles); err != nil { | ||
| return fmt.Errorf("unable to create installer controller: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func loadProviderImages(ctx context.Context, mgr ctrl.Manager, providerImageDir string) ([]providerimages.ProviderImageManifests, error) { | ||
| podName := os.Getenv("POD_NAME") | ||
| podNamespace := os.Getenv("POD_NAMESPACE") | ||
|
|
||
| if podName == "" || podNamespace == "" { | ||
| return nil, errPodIdentityNotSet | ||
| } | ||
|
|
||
| var pod corev1.Pod | ||
| if err := mgr.GetAPIReader().Get(ctx, types.NamespacedName{Name: podName, Namespace: podNamespace}, &pod); err != nil { | ||
| return nil, fmt.Errorf("unable to get pod %s/%s: %w", podNamespace, podName, err) | ||
| } | ||
|
|
||
| imageRefMap, err := providerimages.BuildImageRefMap(pod.Spec, managerName) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to build image ref map from pod spec: %w", err) | ||
| } | ||
|
|
||
| log := ctrl.LoggerFrom(ctx) | ||
|
|
||
| providerProfiles, err := providerimages.ScanProviderImages(log, providerImageDir, imageRefMap) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to scan provider images: %w", err) | ||
| } | ||
|
|
||
| return providerProfiles, nil | ||
| } | ||
|
|
||
| func loadCurrentReleaseImageRefs(ctx context.Context, mgr ctrl.Manager, operatorNamespace string) (sets.Set[string], error) { | ||
| configMap := &corev1.ConfigMap{} | ||
|
|
||
| if err := mgr.GetAPIReader().Get(ctx, types.NamespacedName{ | ||
| Name: providerimages.ConfigMapName, | ||
| Namespace: operatorNamespace, | ||
| }, configMap); err != nil { | ||
| return nil, fmt.Errorf("unable to get ConfigMap %s/%s: %w", operatorNamespace, providerimages.ConfigMapName, err) | ||
| } | ||
|
|
||
| imageRefs, err := providerimages.ImageRefsFromConfigMap(configMap) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to extract image refs from ConfigMap: %w", err) | ||
| } | ||
|
|
||
| return imageRefs, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flag description is inconsistent with runtime behavior.
Line 75 says dev mode can skip pod-spec reading, but Lines 139-149 always require
POD_NAME/POD_NAMESPACEand fetch the Pod.Proposed fix (description-only)
Also applies to: 139-149
🤖 Prompt for AI Agents