-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors and moves buildConfigs and imageStreams related code into n…
…ew files. (#4261) It also refactors a few other resources like deployment etc. Signed-off-by: mik-dass <mrinald7@gmail.com>
- Loading branch information
Showing
16 changed files
with
2,702 additions
and
2,646 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,33 @@ | ||
package kclient | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// GetInputEnvVarsFromStrings generates corev1.EnvVar values from the array of string key=value pairs | ||
// envVars is the array containing the key=value pairs | ||
func GetInputEnvVarsFromStrings(envVars []string) ([]corev1.EnvVar, error) { | ||
var inputEnvVars []corev1.EnvVar | ||
var keys = make(map[string]int) | ||
for _, env := range envVars { | ||
splits := strings.SplitN(env, "=", 2) | ||
if len(splits) < 2 { | ||
return nil, errors.New("invalid syntax for env, please specify a VariableName=Value pair") | ||
} | ||
_, ok := keys[splits[0]] | ||
if ok { | ||
return nil, errors.Errorf("multiple values found for VariableName: %s", splits[0]) | ||
} | ||
|
||
keys[splits[0]] = 1 | ||
|
||
inputEnvVars = append(inputEnvVars, corev1.EnvVar{ | ||
Name: splits[0], | ||
Value: splits[1], | ||
}) | ||
} | ||
return inputEnvVars, 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,103 @@ | ||
package kclient | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestGetInputEnvVarsFromStrings(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
envVars []string | ||
wantedEnvVars []corev1.EnvVar | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Test case 1: with valid two key value pairs", | ||
envVars: []string{"key=value", "key1=value1"}, | ||
wantedEnvVars: []corev1.EnvVar{ | ||
{ | ||
Name: "key", | ||
Value: "value", | ||
}, | ||
{ | ||
Name: "key1", | ||
Value: "value1", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Test case 2: one env var with missing value", | ||
envVars: []string{"key=value", "key1="}, | ||
wantedEnvVars: []corev1.EnvVar{ | ||
{ | ||
Name: "key", | ||
Value: "value", | ||
}, | ||
{ | ||
Name: "key1", | ||
Value: "", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Test case 3: one env var with no value and no =", | ||
envVars: []string{"key=value", "key1"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Test case 4: one env var with multiple values", | ||
envVars: []string{"key=value", "key1=value1=value2"}, | ||
wantedEnvVars: []corev1.EnvVar{ | ||
{ | ||
Name: "key", | ||
Value: "value", | ||
}, | ||
{ | ||
Name: "key1", | ||
Value: "value1=value2", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Test case 5: two env var with same key", | ||
envVars: []string{"key=value", "key=value1"}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Test case 6: one env var with base64 encoded value", | ||
envVars: []string{"key=value", "key1=SSd2ZSBnb3QgYSBsb3ZlbHkgYnVuY2ggb2YgY29jb251dHMhCg=="}, | ||
wantedEnvVars: []corev1.EnvVar{ | ||
{ | ||
Name: "key", | ||
Value: "value", | ||
}, | ||
{ | ||
Name: "key1", | ||
Value: "SSd2ZSBnb3QgYSBsb3ZlbHkgYnVuY2ggb2YgY29jb251dHMhCg==", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
envVars, err := GetInputEnvVarsFromStrings(tt.envVars) | ||
|
||
if err == nil && !tt.wantErr { | ||
if !reflect.DeepEqual(tt.wantedEnvVars, envVars) { | ||
t.Errorf("corev1.Env values are not matching with expected values, expected: %v, got %v", tt.wantedEnvVars, envVars) | ||
} | ||
} else if err == nil && tt.wantErr { | ||
t.Error("error was expected, but no error was returned") | ||
} else if err != nil && !tt.wantErr { | ||
t.Errorf("test failed, no error was expected, but got unexpected error: %s", err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.