Skip to content

Commit

Permalink
#29 - refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
apanasiuk-el committed Nov 21, 2024
1 parent 57d810c commit 1d7baf1
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func createClusterCTLConfigFile(output []byte) (string, error) {
return "", err
}

return util.CreateTempYAMLFile("/tmp", clusterCTL.Metadata["name"], data)
return util.CreateTempYAMLFile(os.TempDir(), clusterCTL.Metadata["name"], data)
}

func (cc *ClusterCommands) getClusterCTLConfig() (string, string, error) {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (cc *ClusterCommands) mergeKubeConfigs(clusterContext []byte) error {
return err
}

file, err := createManifestFile(object, "/tmp", cc.Conf.Name+"-"+cc.Conf.ClusterProvider+"-kubeconfig")
file, err := createManifestFile(object, os.TempDir(), cc.Conf.Name+"-"+cc.Conf.ClusterProvider+"-kubeconfig")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster_capa.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewAWSClusterStaticIdentityConfig(ac *aws_provider.AwsConfigure) *AWSCluste
},
AWSIAMControllerSecret: v1.Secret(awsIAMControllerSecret, awsClusterStaticIdentityNamespace),
SecretApplyConfiguration: v1.Secret(awsClusterStaticIdentitySecret, awsClusterStaticIdentityNamespace),
ManifestFilesDir: filepath.Join("/tmp", awsClusterStaticIdentityName),
ManifestFilesDir: filepath.Join(os.TempDir(), awsClusterStaticIdentityName),
}

profile, err := ac.RenderAWSConfigProfile(awsIAMControllerCredentialsTemplate)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster_capg.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type GCPClusterIdentityConfig struct {
func NewGCPClusterIdentityConfig(gcp *google_provider.GCPConfigure) *GCPClusterIdentityConfig {
gcpcc := &GCPClusterIdentityConfig{
SecretApplyConfiguration: v1.Secret(gcpClusterIdentitySecret, gcpClusterIdentityNamespace),
ManifestFilesDir: filepath.Join("/tmp", gcpClusterIdentityName),
ManifestFilesDir: filepath.Join(os.TempDir(), gcpClusterIdentityName),
}

gcpcc.SecretApplyConfiguration.Type = &gcpClusterIdentitySecretType
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster_capz.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewAzureClusterIdentityConfig(ac *azure_provider.AzureConfigure) *AzureClus
},
},
SecretApplyConfiguration: v1.Secret(azureClusterIdentitySecret, azureClusterIdentityNamespace),
ManifestFilesDir: filepath.Join("/tmp", azureClusterIdentityName),
ManifestFilesDir: filepath.Join(os.TempDir(), azureClusterIdentityName),
}

acic.SecretApplyConfiguration.Type = &azureClusterIdentitySecretType
Expand Down
4 changes: 2 additions & 2 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func flagsConfig() []cli.Flag {
altsrc.NewStringFlag(
&cli.StringFlag{
Name: "cluster-provider",
Usage: "select cluster provider to provision clusters",
Usage: "cluster provider for provisioning",
Aliases: []string{"cp"},
EnvVars: []string{"RMK_CLUSTER_PROVIDER"},
Value: util.LocalClusterProvider,
Expand All @@ -107,7 +107,7 @@ func flagsConfig() []cli.Flag {
&cli.StringFlag{
Category: gcpFlagsCategory,
Name: "google-application-credentials",
Usage: "GCP service account credentials file path in JSON format",
Usage: "path to GCP service account credentials JSON file",
Aliases: []string{"gac"},
EnvVars: []string{"RMK_GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_APPLICATION_CREDENTIALS"},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3d.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (k *K3DCommands) createDeleteK3DCluster() error {
k.Ctx.Command.Category, k.SpecCMD.StderrBuf.String())
}

k3dConfig, err := util.CreateTempYAMLFile("/tmp", k.Ctx.Command.Category+"-config", k.SpecCMD.StdoutBuf.Bytes())
k3dConfig, err := util.CreateTempYAMLFile("os.TempDir()", k.Ctx.Command.Category+"-config", k.SpecCMD.StdoutBuf.Bytes())
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/aws_provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (a *AwsConfigure) GetAWSClusterContext(clusterName string) ([]byte, error)
client := eks.NewFromConfig(cfg)
cluster, err := client.DescribeCluster(a.Ctx, &eks.DescribeClusterInput{Name: aws.String(clusterName)})
if err != nil {
return nil, fmt.Errorf("kubecontext to %s provider's for cluster %s not found",
return nil, fmt.Errorf("kubecontext for %s provider's %s cluster not found",
strings.ToUpper(AWSClusterProvider), clusterName)
}

Expand Down Expand Up @@ -390,7 +390,7 @@ func (a *AwsConfigure) generateUserKubeconfig(cluster *eksType.Cluster) ([]byte,

out, err := clientcmd.Write(*cfg)
if err != nil {
return nil, fmt.Errorf("failed to serialize kubeconfig to yaml: %w", err)
return nil, fmt.Errorf("failed to serialize kubeconfig to YAML: %w", err)
}

return out, nil
Expand Down
4 changes: 2 additions & 2 deletions providers/azure_provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ func (ac *AzureConfigure) GetAzureClusterContext(groupName, clusterName string)

credentials, err := ac.ManagedClustersClient.ListClusterAdminCredentials(ac.Ctx, groupName, clusterName, nil)
if err != nil {
return nil, fmt.Errorf("kubecontext to %s provider's for cluster %s not found",
return nil, fmt.Errorf("kubecontext for %s provider's %s cluster not found",
cpTitle, clusterName)
}

if len(credentials.CredentialResults.Kubeconfigs) == 1 {
return credentials.CredentialResults.Kubeconfigs[0].Value, nil
}

return nil, fmt.Errorf("kubecontext to %s provider's for cluster %s not found",
return nil, fmt.Errorf("kubecontext for %s provider's %s cluster not found",
cpTitle, clusterName)
}

Expand Down
4 changes: 2 additions & 2 deletions providers/google_provider/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (gcp *GCPConfigure) GetGCPClusterContext(clusterName string) ([]byte, error
return gcp.generateUserKubeconfig(cluster)
}

return nil, fmt.Errorf("kubecontext to %s provider's for cluster %s not found",
return nil, fmt.Errorf("kubecontext for %s provider's %s cluster not found",
strings.ToUpper(GoogleClusterProvider), clusterName)
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func (gcp *GCPConfigure) generateUserKubeconfig(cluster *container.Cluster) ([]b

out, err := clientcmd.Write(*cfg)
if err != nil {
return nil, fmt.Errorf("failed to serialize kubeconfig to yaml: %w", err)
return nil, fmt.Errorf("failed to serialize kubeconfig to YAML: %w", err)
}

return out, nil
Expand Down

0 comments on commit 1d7baf1

Please sign in to comment.