generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #709 from wzshiming/feat/kwokctl-config
[kwokctl] Add config subcommand
- Loading branch information
Showing
13 changed files
with
346 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,45 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 config provides the kwokctl config command. | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kwok/pkg/kwokctl/cmd/config/reset" | ||
"sigs.k8s.io/kwok/pkg/kwokctl/cmd/config/tidy" | ||
"sigs.k8s.io/kwok/pkg/kwokctl/cmd/config/view" | ||
) | ||
|
||
// NewCommand returns a new cobra.Command for config | ||
func NewCommand(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "config [command]", | ||
Short: "Manage [reset, tidy, view] default config", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return cmd.Help() | ||
}, | ||
} | ||
|
||
cmd.AddCommand(reset.NewCommand(ctx)) | ||
cmd.AddCommand(tidy.NewCommand(ctx)) | ||
cmd.AddCommand(view.NewCommand(ctx)) | ||
return cmd | ||
} |
This file contains 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,56 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 reset provides the kwokctl config reset command. | ||
package reset | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kwok/pkg/config" | ||
"sigs.k8s.io/kwok/pkg/consts" | ||
"sigs.k8s.io/kwok/pkg/kwokctl/dryrun" | ||
"sigs.k8s.io/kwok/pkg/utils/file" | ||
"sigs.k8s.io/kwok/pkg/utils/path" | ||
) | ||
|
||
// NewCommand returns a new cobra.Command for config reset | ||
func NewCommand(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "reset", | ||
Short: "Remove the default config file", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runE(cmd.Context()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func runE(_ context.Context) error { | ||
p := path.Join(config.WorkDir, consts.ConfigName) | ||
if dryrun.DryRun { | ||
dryrun.PrintMessage("# Removing config file %s", p) | ||
return nil | ||
} | ||
err := file.Remove(p) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains 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,56 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 tidy provides a command to tidy the config file | ||
package tidy | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kwok/pkg/config" | ||
"sigs.k8s.io/kwok/pkg/consts" | ||
"sigs.k8s.io/kwok/pkg/kwokctl/dryrun" | ||
"sigs.k8s.io/kwok/pkg/utils/path" | ||
) | ||
|
||
// NewCommand returns a new cobra.Command for config save | ||
func NewCommand(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "tidy", | ||
Short: "Tidy the default config file with --config", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runE(cmd.Context()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func runE(ctx context.Context) error { | ||
list := config.GetFromContext(ctx) | ||
p := path.Join(config.WorkDir, consts.ConfigName) | ||
if dryrun.DryRun { | ||
dryrun.PrintMessage("# Tidy the config file") | ||
return nil | ||
} | ||
err := config.Save(ctx, p, list) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains 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,57 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
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 view provides the kwokctl config view command. | ||
package view | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"sigs.k8s.io/kwok/pkg/config" | ||
"sigs.k8s.io/kwok/pkg/consts" | ||
"sigs.k8s.io/kwok/pkg/kwokctl/dryrun" | ||
"sigs.k8s.io/kwok/pkg/utils/path" | ||
) | ||
|
||
// NewCommand returns a new cobra.Command for config view | ||
func NewCommand(ctx context.Context) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Args: cobra.NoArgs, | ||
Use: "view", | ||
Short: "Display the default config file with --config", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runE(cmd.Context()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func runE(ctx context.Context) error { | ||
p := path.Join(config.WorkDir, consts.ConfigName) | ||
if dryrun.DryRun { | ||
dryrun.PrintMessage("# Displaying config file %s", p) | ||
return nil | ||
} | ||
list := config.GetFromContext(ctx) | ||
err := config.SaveTo(ctx, os.Stdout, list) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains 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 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 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,30 @@ | ||
## kwokctl config | ||
|
||
Manage [reset, tidy, view] default config | ||
|
||
``` | ||
kwokctl config [command] [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for config | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-c, --config stringArray config path (default [~/.kwok/kwok.yaml]) | ||
--dry-run Print the command that would be executed, but do not execute it | ||
--name string cluster name (default "kwok") | ||
-v, --v log-level number for the log level verbosity (DEBUG, INFO, WARN, ERROR) or (-4, 0, 4, 8) (default INFO) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kwokctl](kwokctl.md) - kwokctl is a tool to streamline the creation and management of clusters, with nodes simulated by kwok | ||
* [kwokctl config reset](kwokctl_config_reset.md) - Remove the default config file | ||
* [kwokctl config tidy](kwokctl_config_tidy.md) - Tidy the default config file with --config | ||
* [kwokctl config view](kwokctl_config_view.md) - Display the default config file with --config | ||
|
Oops, something went wrong.