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

rename sandbox.yaml to ksctl.yaml #6

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestUpdateUserSignupLacksPermissions(t *testing.T) {
}, "updated")

// then
require.EqualError(t, err, "sandbox command failed: the token in your sandbox.yaml file is missing")
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
AssertUserSignupSpec(t, fakeClient, userSignup)
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/cmd/adm/generate_cli_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
f := generateFlags{}
command := &cobra.Command{
Use: "generate-cli-configs --sandbox-config=<path-to-sandbox-config-file>",
Short: "Generate sandbox.yaml files",
Long: `Generate sandbox.yaml files, that is used by sandbox-cli, for every ServiceAccount defined in the given sandbox-config.yaml file`,
Short: "Generate ksctl.yaml files",
Long: `Generate ksctl.yaml files, that is used by sandbox-cli, for every ServiceAccount defined in the given sandbox-config.yaml file`,

Check warning on line 40 in pkg/cmd/adm/generate_cli_configs.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/generate_cli_configs.go#L39-L40

Added lines #L39 - L40 were not covered by tests
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
Expand All @@ -49,7 +49,7 @@
command.Flags().BoolVarP(&f.dev, "dev", "d", false, "If running in a dev cluster")

configDirPath := fmt.Sprintf("%s/src/github.com/kubesaw/ksctl/out/config", os.Getenv("GOPATH"))
command.Flags().StringVarP(&f.outDir, "out-dir", "o", configDirPath, "Directory where generated sandbox.yaml files should be stored")
command.Flags().StringVarP(&f.outDir, "out-dir", "o", configDirPath, "Directory where generated ksctl.yaml files should be stored")

Check warning on line 52 in pkg/cmd/adm/generate_cli_configs.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/adm/generate_cli_configs.go#L52

Added line #L52 was not covered by tests

defaultKubeconfigPath := ""
if home := homedir.HomeDir(); home != "" {
Expand Down Expand Up @@ -94,7 +94,7 @@
kubeconfigPaths: flags.kubeconfigs,
}

// sandboxUserConfigsPerName contains all sandboxUserConfig objects that will be marshalled to sandbox.yaml files
// sandboxUserConfigsPerName contains all sandboxUserConfig objects that will be marshalled to ksctl.yaml files
sandboxUserConfigsPerName := map[string]configuration.SandboxUserConfig{}

// use host API either from the sandbox-config.yaml or from kubeconfig if --dev flag was used
Expand Down Expand Up @@ -148,11 +148,11 @@
if err != nil {
return err
}
path := pathDir + "/sandbox.yaml"
path := pathDir + "/ksctl.yaml"
if err := os.WriteFile(path, content, 0600); err != nil {
return err
}
term.Printlnf("sandbox.yaml file for %s was stored in %s", name, path)
term.Printlnf("ksctl.yaml file for %s was stored in %s", name, path)
}
return nil
}
Expand All @@ -169,7 +169,7 @@
type tokenPerSA map[string]string

func generateForCluster(ctx *generateContext, clusterType configuration.ClusterType, clusterName string, clusterSpec assets.ClusterConfig, sandboxUserConfigsPerName map[string]configuration.SandboxUserConfig) error {
ctx.PrintContextSeparatorf("Generating the content of the sandbox.yaml files for %s cluster running at %s", clusterName, clusterSpec.API)
ctx.PrintContextSeparatorf("Generating the content of the ksctl.yaml files for %s cluster running at %s", clusterName, clusterSpec.API)

// find config we can build client for the cluster from
externalClient, err := buildClientFromKubeconfigFiles(ctx, clusterSpec.API, ctx.kubeconfigPaths)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/adm/generate_cli_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func verifySandboxUserConfigFiles(t *testing.T, tempDir string, clusterAssertion
require.NoError(t, err)

assert.Len(t, userDirInfo, 1)
assert.Equal(t, "sandbox.yaml", userDirInfo[0].Name())
assert.Equal(t, "ksctl.yaml", userDirInfo[0].Name())
content, err := os.ReadFile(path.Join(tempDir, userDir.Name(), userDirInfo[0].Name()))
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/adm/unregister_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestUnregisterMemberWhenUnknownClusterName(t *testing.T) {

// then
require.Error(t, err)
assert.Contains(t, err.Error(), "the provided cluster-name 'some' is not present in your sandbox.yaml file.")
assert.Contains(t, err.Error(), "the provided cluster-name 'some' is not present in your ksctl.yaml file.")
AssertToolchainClusterSpec(t, fakeClient, toolchainCluster)
assert.NotContains(t, term.Output(), "!!! DANGER ZONE !!!")
assert.NotContains(t, term.Output(), "THIS COMMAND WILL CAUSE UNREGISTER MEMBER CLUSTER FORM HOST CLUSTER. MAKE SURE THERE IS NO USERS LEFT IN THE MEMBER CLUSTER BEFORE UNREGISTERING IT")
Expand All @@ -118,6 +118,6 @@ func TestUnregisterMemberLacksPermissions(t *testing.T) {
err := UnregisterMemberCluster(ctx, "member1")

// then
require.EqualError(t, err, "sandbox command failed: the token in your sandbox.yaml file is missing")
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
AssertToolchainClusterSpec(t, fakeClient, toolchainCluster)
}
2 changes: 1 addition & 1 deletion pkg/cmd/approve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestApprove(t *testing.T) {

// then
require.Error(t, err)
assert.Contains(t, err.Error(), "the provided cluster-name 'non-existent-member' is not present in your sandbox.yaml file")
assert.Contains(t, err.Error(), "the provided cluster-name 'non-existent-member' is not present in your ksctl.yaml file")
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/ban_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,6 @@ func TestCreateBannedUserLacksPermissions(t *testing.T) {
})

// then
require.EqualError(t, err, "sandbox command failed: the token in your sandbox.yaml file is missing")
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
AssertUserSignupSpec(t, fakeClient, userSignup)
}
2 changes: 1 addition & 1 deletion pkg/cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestDeleteLacksPermissions(t *testing.T) {
err := cmd.Delete(ctx, userSignup.Name)

// then
require.EqualError(t, err, "sandbox command failed: the token in your sandbox.yaml file is missing")
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
AssertUserSignupSpec(t, fakeClient, userSignup)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/retarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestRetarget(t *testing.T) {

// then
require.Error(t, err)
assert.Contains(t, err.Error(), "the provided cluster-name 'non-existent-member' is not present in your sandbox.yaml file")
assert.Contains(t, err.Error(), "the provided cluster-name 'non-existent-member' is not present in your ksctl.yaml file")
})

t.Run("setting target cluster failed", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Execute() {
}

func init() {
rootCmd.PersistentFlags().StringVar(&configuration.ConfigFileFlag, "config", "", "config file (default is $HOME/.sandbox.yaml)")
rootCmd.PersistentFlags().StringVar(&configuration.ConfigFileFlag, "config", "", "config file (default is $HOME/.ksctl.yaml)")
rootCmd.PersistentFlags().BoolVarP(&configuration.Verbose, "verbose", "v", false, "print extra info/debug messages")

// commands with go runtime client
Expand Down
17 changes: 14 additions & 3 deletions pkg/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@
if err != nil {
return SandboxUserConfig{}, "", errs.Wrap(err, "unable to read home directory")
}
path = filepath.Join(home, ".sandbox.yaml")
path = filepath.Join(home, ".ksctl.yaml")

Check warning on line 36 in pkg/configuration/configuration.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/configuration.go#L36

Added line #L36 was not covered by tests

if _, err := os.Stat(path); err != nil && os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(home, ".sandbox.yaml")); err != nil && !os.IsNotExist(err) {
return SandboxUserConfig{}, "", err
} else if err == nil {
path = filepath.Join(home, ".sandbox.yaml")
term.Println("The default location of ~/.sandbox.yaml file is deprecated. Rename it to ~/.ksctl.yaml")

Check warning on line 43 in pkg/configuration/configuration.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/configuration.go#L38-L43

Added lines #L38 - L43 were not covered by tests
}
} else if err != nil {
return SandboxUserConfig{}, "", err

Check warning on line 46 in pkg/configuration/configuration.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/configuration.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}
}

info, err := os.Stat(path)
Expand Down Expand Up @@ -112,7 +123,7 @@
if !ok {
// if not found, then also try original format (to cover situation when camel case is used)
if clusterDef, ok = sandboxUserConfig.ClusterAccessDefinitions[clusterName]; !ok {
return ClusterAccessDefinition{}, fmt.Errorf("the provided cluster-name '%s' is not present in your sandbox.yaml file. The available cluster names are\n"+
return ClusterAccessDefinition{}, fmt.Errorf("the provided cluster-name '%s' is not present in your ksctl.yaml file. The available cluster names are\n"+
"------------------------\n%s\n"+
"------------------------", clusterName, strings.Join(getAllClusterNames(sandboxUserConfig), "\n"))
}
Expand Down Expand Up @@ -160,7 +171,7 @@
return ClusterConfig{}, err
}
if clusterDef.Token == "" {
return ClusterConfig{}, fmt.Errorf("sandbox command failed: the token in your sandbox.yaml file is missing")
return ClusterConfig{}, fmt.Errorf("sandbox command failed: the token in your ksctl.yaml file is missing")
}
var sandboxNamespace string
if clusterName == HostName {
Expand Down
6 changes: 3 additions & 3 deletions pkg/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestLoadClusterConfig(t *testing.T) {
cfg, err := configuration.LoadClusterConfig(term, clusterName)

// then
require.EqualError(t, err, "sandbox command failed: the token in your sandbox.yaml file is missing")
require.EqualError(t, err, "sandbox command failed: the token in your ksctl.yaml file is missing")
assert.Empty(t, cfg.Token)
})
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestLoadClusterConfig(t *testing.T) {

// then
require.Error(t, err)
assert.Contains(t, err.Error(), "the provided cluster-name 'dummy' is not present in your sandbox.yaml file. The available cluster names are")
assert.Contains(t, err.Error(), "the provided cluster-name 'dummy' is not present in your ksctl.yaml file. The available cluster names are")
})

for _, clusterConfigParam := range []ClusterDefinitionWithName{Host(), Member()} {
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestLoadingClusterConfigWithNonexistentClusterName(t *testing.T) {

// then
require.Error(t, err)
assert.Contains(t, err.Error(), "the provided cluster-name 'dummy' is not present in your sandbox.yaml file. The available cluster names are")
assert.Contains(t, err.Error(), "the provided cluster-name 'dummy' is not present in your ksctl.yaml file. The available cluster names are")
assert.Contains(t, err.Error(), "host")
assert.Contains(t, err.Error(), "member-1")
assert.Empty(t, cfg.SandboxNamespace)
Expand Down
Loading