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

chore: add --no-diff flag for convert-to-1.0 cmd #528

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all 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: 7 additions & 2 deletions pkg/cmd/cluster/covert_to_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ type ConvertToV1Options struct {
f cmdutil.Factory
Dynamic dynamic.Interface
DryRun bool
NoDiff bool
Name string
Namespace string
genericiooptions.IOStreams
Expand Down Expand Up @@ -319,6 +320,7 @@ func NewConvertToV1Cmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *c
},
}
cmd.Flags().BoolVar(&o.DryRun, "dry-run", false, "dry run mode")
cmd.Flags().BoolVar(&o.NoDiff, "no-diff", false, "only print the new cluster yaml")
return cmd
}

Expand Down Expand Up @@ -378,10 +380,10 @@ func (o *ConvertToV1Options) Run() error {
if existUnsupportedSpec {
return fmt.Errorf(`cluster "%s" has unknown clusterVersion or componentDefinition, you can replace with accorrding ComponentDefinition with 1.0 api`, o.Name)
}
fmt.Println(printer.BoldYellow(fmt.Sprintf("Cluster %s will be converted to v1 with output as yaml.", o.Name)))
if o.DryRun {
return nil
}
fmt.Println(printer.BoldYellow(fmt.Sprintf("Cluster %s will be converted to v1 with output as yaml.", o.Name)))
if err = prompt.Confirm(nil, o.In, "", "Please type 'Yes/yes' to confirm your operation:"); err != nil {
return err
}
Expand Down Expand Up @@ -526,7 +528,10 @@ func (o *ConvertToV1Options) printDiff(clusterV1Alpha1 *kbappsv1alpha1.Cluster,
clusterV1.ObjectMeta.ManagedFields = nil
clusterV1Alpha1Srr, _ := yaml.Marshal(clusterV1Alpha1)
clusterV1Str, _ := yaml.Marshal(clusterV1)

if o.NoDiff {
fmt.Println(string(clusterV1Str))
return
}
getDiffContext := func(isV1Cluster bool) string {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(string(clusterV1Alpha1Srr), string(clusterV1Str), false)
Expand Down
Loading