|
|
@@ -2,9 +2,9 @@ package deploy
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
+ "fmt"
|
|
|
|
|
|
+ "github.com/fatih/color"
|
|
|
api "github.com/porter-dev/porter/api/client"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
)
|
|
|
@@ -19,43 +19,19 @@ type SharedOpts struct {
|
|
|
OverrideTag string
|
|
|
Method DeployBuildType
|
|
|
AdditionalEnv map[string]string
|
|
|
- EnvGroups []string
|
|
|
-}
|
|
|
-
|
|
|
-func getEnvGroupNameVersion(group string) (string, uint, error) {
|
|
|
- if !strings.Contains(group, "@") {
|
|
|
- return group, 0, nil
|
|
|
- }
|
|
|
-
|
|
|
- envGroupSpl := strings.Split(group, "@")
|
|
|
- envGroupName := envGroupSpl[0]
|
|
|
- envGroupVersion := uint64(0)
|
|
|
-
|
|
|
- envGroupVersion, err := strconv.ParseUint(envGroupSpl[1], 10, 32)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return "", 0, err
|
|
|
- }
|
|
|
-
|
|
|
- return envGroupName, uint(envGroupVersion), nil
|
|
|
+ EnvGroups []types.EnvGroupMeta
|
|
|
}
|
|
|
|
|
|
func coalesceEnvGroups(
|
|
|
client *api.Client,
|
|
|
projectID, clusterID uint,
|
|
|
namespace string,
|
|
|
- envGroups []string,
|
|
|
+ envGroups []types.EnvGroupMeta,
|
|
|
config map[string]interface{},
|
|
|
) error {
|
|
|
for _, group := range envGroups {
|
|
|
- if group == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- envGroupName, envGroupVersion, err := getEnvGroupNameVersion(group)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ if group.Name == "" {
|
|
|
+ return fmt.Errorf("env group name cannot be empty")
|
|
|
}
|
|
|
|
|
|
envGroup, err := client.GetEnvGroup(
|
|
|
@@ -64,12 +40,34 @@ func coalesceEnvGroups(
|
|
|
clusterID,
|
|
|
namespace,
|
|
|
&types.GetEnvGroupRequest{
|
|
|
- Name: envGroupName,
|
|
|
- Version: envGroupVersion,
|
|
|
+ Name: group.Name,
|
|
|
+ Version: group.Version,
|
|
|
},
|
|
|
)
|
|
|
|
|
|
- if err != nil {
|
|
|
+ if err != nil && err.Error() == "env group not found" {
|
|
|
+ if group.Namespace == "" {
|
|
|
+ return fmt.Errorf("env group namespace cannot be empty")
|
|
|
+ }
|
|
|
+
|
|
|
+ color.New(color.FgBlue, color.Bold).
|
|
|
+ Printf("Env group '%s' does not exist in the target namespace '%s'\n", group.Name, namespace)
|
|
|
+ color.New(color.FgBlue, color.Bold).
|
|
|
+ Printf("Cloning env group '%s' from namespace '%s' to target namespace '%s'\n",
|
|
|
+ group.Name, group.Namespace, namespace)
|
|
|
+
|
|
|
+ envGroup, err = client.CloneEnvGroup(
|
|
|
+ context.Background(), projectID, clusterID, group.Namespace,
|
|
|
+ &types.CloneEnvGroupRequest{
|
|
|
+ Name: group.Name,
|
|
|
+ Namespace: namespace,
|
|
|
+ },
|
|
|
+ )
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ } else if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|