Skip to content

Commit

Permalink
rename sandbox.yaml to ksctl.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek committed Mar 14, 2024
1 parent 7ac20a4 commit da7c46b
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 22 deletions.
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 @@ func NewGenerateCliConfigsCmd() *cobra.Command {
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`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, _ []string) error {
term := ioutils.NewTerminal(cmd.InOrStdin, cmd.OutOrStdout)
Expand All @@ -49,7 +49,7 @@ func NewGenerateCliConfigsCmd() *cobra.Command {
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")

defaultKubeconfigPath := ""
if home := homedir.HomeDir(); home != "" {
Expand Down Expand Up @@ -94,7 +94,7 @@ func generate(term ioutils.Terminal, flags generateFlags, newClient NewClientFro
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 @@ func writeSandboxUserConfigs(term ioutils.Terminal, configDirPath string, sandbo
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 generateContext struct {
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 @@ func Load(term ioutils.Terminal) (SandboxUserConfig, string, error) {
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")

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")
}
} else if err != nil {
return SandboxUserConfig{}, "", err
}
}

info, err := os.Stat(path)
Expand Down Expand Up @@ -112,7 +123,7 @@ func loadClusterAccessDefinition(sandboxUserConfig SandboxUserConfig, clusterNam
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 @@ func LoadClusterConfig(term ioutils.Terminal, clusterName string) (ClusterConfig
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

0 comments on commit da7c46b

Please sign in to comment.