-
Notifications
You must be signed in to change notification settings - Fork 478
OCPEDGE-2416: Add oc adm transition topology command for SNO to HA transitions #2295
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
Merged
openshift-merge-bot
merged 2 commits into
openshift:main
from
jaypoulz:OCPEDGE-2416-oc-adm-transition
Sep 22, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,7 @@ | ||
| # See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md | ||
| # This file just uses aliases defined in OWNERS_ALIASES. | ||
|
|
||
| approvers: | ||
| - openshift-edge-approvers | ||
| reviewers: | ||
| - openshift-edge-reviewers |
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,163 @@ | ||
| package transition | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
| configv1client "github.com/openshift/client-go/config/clientset/versioned" | ||
| operatorv1client "github.com/openshift/client-go/operator/clientset/versioned" | ||
| v1helpers "github.com/openshift/library-go/pkg/operator/v1helpers" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/cli-runtime/pkg/genericclioptions" | ||
| kcmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
| "k8s.io/kubectl/pkg/util/templates" | ||
| ) | ||
|
|
||
| var ( | ||
| statusLong = templates.LongDesc(` | ||
| Monitor topology transition progress. | ||
|
|
||
| Displays the current control plane and infrastructure topology status, | ||
| and shows the cluster-config-operator transition conditions to monitor | ||
| transition progress. | ||
| `) | ||
|
|
||
| statusExample = templates.Examples(` | ||
| # Monitor transition progress | ||
| oc adm transition status | ||
| `) | ||
| ) | ||
|
|
||
| // statusOptions holds options for the status subcommand | ||
| type statusOptions struct { | ||
| configClient configv1client.Interface | ||
| operatorClient operatorv1client.Interface | ||
|
|
||
| genericclioptions.IOStreams | ||
| } | ||
|
|
||
| // newCmdStatus creates the status subcommand | ||
| func newCmdStatus(f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { | ||
| o := &statusOptions{ | ||
| IOStreams: streams, | ||
| } | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "status", | ||
| Short: "Monitor topology transition progress", | ||
| Long: statusLong, | ||
| Example: statusExample, | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| kcmdutil.CheckErr(o.complete(f, cmd, args)) | ||
| kcmdutil.CheckErr(o.run(cmd.Context())) | ||
| }, | ||
| } | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| // complete sets up all required fields from the factory | ||
| func (o *statusOptions) complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error { | ||
| restConfig, err := f.ToRESTConfig() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get REST config: %w", err) | ||
| } | ||
|
|
||
| o.configClient, err = configv1client.NewForConfig(restConfig) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create config client: %w", err) | ||
| } | ||
|
|
||
| o.operatorClient, err = operatorv1client.NewForConfig(restConfig) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create operator client: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // run executes the status subcommand | ||
| func (o *statusOptions) run(ctx context.Context) error { | ||
| ctx, cancel := context.WithTimeout(ctx, apiRequestTimeout) | ||
| defer cancel() | ||
|
|
||
| if err := o.printTopologyStatus(ctx); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return o.printTopologyTransitionStatus(ctx) | ||
| } | ||
|
|
||
| // printTopologyStatus will output the Control Plane and Infrastructure topologies from spec and status | ||
| func (o *statusOptions) printTopologyStatus(ctx context.Context) error { | ||
| infra, err := o.configClient.ConfigV1().Infrastructures().Get(ctx, infrastructureResourceName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get Infrastructure resource: %w", err) | ||
| } | ||
|
|
||
| notSet := "(not set)" | ||
| cpSpecTopology := string(infra.Spec.ControlPlaneTopology) | ||
| if cpSpecTopology == "" { | ||
| cpSpecTopology = notSet | ||
| } | ||
|
|
||
| cpStatusTopology := string(infra.Status.ControlPlaneTopology) | ||
| if cpStatusTopology == "" { | ||
| cpStatusTopology = notSet | ||
| } | ||
|
|
||
| infraStatusTopology := string(infra.Status.InfrastructureTopology) | ||
| if infraStatusTopology == "" { | ||
| infraStatusTopology = notSet | ||
| } | ||
|
|
||
| var output strings.Builder | ||
| statusOutput := ` | ||
| Control Plane Topology: | ||
| Spec (desired): %s | ||
| Status (current): %s | ||
|
|
||
| Infrastructure Topology: | ||
| Status (current): %s | ||
| ` | ||
| fmt.Fprintf(&output, statusOutput, cpSpecTopology, cpStatusTopology, infraStatusTopology) | ||
|
|
||
| if _, err := io.WriteString(o.Out, output.String()); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (o *statusOptions) printTopologyTransitionStatus(ctx context.Context) error { | ||
| operatorConfig, err := o.operatorClient.OperatorV1().Configs().Get(ctx, clusterConfigOperatorResourceName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get configs.operator.openshift.io/cluster: %w", err) | ||
| } | ||
|
|
||
| // Pull out the relevant conditions from CCO | ||
| progressingCond := v1helpers.FindOperatorCondition(operatorConfig.Status.Conditions, topologyTransitionControllerProgressingCondition) | ||
| upgradeableCond := v1helpers.FindOperatorCondition(operatorConfig.Status.Conditions, topologyTransitionControllerUpgradeableCondition) | ||
|
|
||
| var output strings.Builder | ||
| fmt.Fprintln(&output, "\nTransition Status") | ||
| fmt.Fprintln(&output, formatTopologyConditionStatus("Progressing", progressingCond)) | ||
| fmt.Fprintln(&output, formatTopologyConditionStatus("Upgradeable", upgradeableCond)) | ||
|
|
||
| _, err = io.WriteString(o.Out, output.String()) | ||
| return err | ||
| } | ||
|
|
||
| // formatTopologyConditionStatus formats the provided topology transition condition status under a 'label' heading | ||
| func formatTopologyConditionStatus(label string, cond *operatorv1.OperatorCondition) string { | ||
| if cond == nil { | ||
| return fmt.Sprintf(" %s: Condition not available\n", label) | ||
| } | ||
|
|
||
| return fmt.Sprintf(" %s\n Status: %s\n Reason: %s\n Condition: %s\n", label, cond.Status, cond.Reason, cond.Message) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.