mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Allow env to be updated via specific key in resource
This commit is contained in:
@@ -72,7 +72,8 @@ func TestSetEnvLocal(t *testing.T) {
|
||||
Filenames: []string{"../../../../examples/storage/cassandra/cassandra-controller.yaml"}},
|
||||
Out: buf,
|
||||
Local: true}
|
||||
err := opts.Complete(f, cmd, []string{"env=prod"})
|
||||
opts.Complete(f, cmd)
|
||||
err := opts.Validate([]string{"env=prod"})
|
||||
if err == nil {
|
||||
err = opts.RunEnv(f)
|
||||
}
|
||||
@@ -109,7 +110,8 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
|
||||
Filenames: []string{"../../../../test/fixtures/pkg/kubectl/cmd/set/multi-resource-yaml.yaml"}},
|
||||
Out: buf,
|
||||
Local: true}
|
||||
err := opts.Complete(f, cmd, []string{"env=prod"})
|
||||
opts.Complete(f, cmd)
|
||||
err := opts.Validate([]string{"env=prod"})
|
||||
if err == nil {
|
||||
err = opts.RunEnv(f)
|
||||
}
|
||||
@@ -124,11 +126,13 @@ func TestSetMultiResourcesEnvLocal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSetEnvRemote(t *testing.T) {
|
||||
out := new(bytes.Buffer)
|
||||
inputs := []struct {
|
||||
object runtime.Object
|
||||
apiPrefix, apiGroup, apiVersion string
|
||||
testAPIGroup string
|
||||
args []string
|
||||
opts *EnvOptions
|
||||
}{
|
||||
{
|
||||
object: &extensionsv1beta1.ReplicaSet{
|
||||
@@ -149,6 +153,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "extensions", apiVersion: "v1beta1",
|
||||
args: []string{"replicaset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta2.ReplicaSet{
|
||||
@@ -169,6 +174,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta2",
|
||||
args: []string{"replicaset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1.ReplicaSet{
|
||||
@@ -189,6 +195,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"replicaset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &extensionsv1beta1.DaemonSet{
|
||||
@@ -209,6 +216,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "extensions", apiVersion: "v1beta1",
|
||||
args: []string{"daemonset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta2.DaemonSet{
|
||||
@@ -229,6 +237,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta2",
|
||||
args: []string{"daemonset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1.DaemonSet{
|
||||
@@ -249,6 +258,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"daemonset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &extensionsv1beta1.Deployment{
|
||||
@@ -269,6 +279,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "extensions", apiVersion: "v1beta1",
|
||||
args: []string{"deployment", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta1.Deployment{
|
||||
@@ -289,6 +300,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta1",
|
||||
args: []string{"deployment", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta2.Deployment{
|
||||
@@ -309,6 +321,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta2",
|
||||
args: []string{"deployment", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1.Deployment{
|
||||
@@ -329,6 +342,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"deployment", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta1.StatefulSet{
|
||||
@@ -349,6 +363,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "apps",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta1",
|
||||
args: []string{"statefulset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1beta2.StatefulSet{
|
||||
@@ -369,6 +384,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "apps",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1beta2",
|
||||
args: []string{"statefulset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1.StatefulSet{
|
||||
@@ -389,6 +405,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "apps",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"statefulset", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &batchv1.Job{
|
||||
@@ -409,6 +426,7 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "batch",
|
||||
apiPrefix: "/apis", apiGroup: "batch", apiVersion: "v1",
|
||||
args: []string{"job", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &v1.ReplicationController{
|
||||
@@ -429,6 +447,54 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
testAPIGroup: "",
|
||||
apiPrefix: "/api", apiGroup: "", apiVersion: "v1",
|
||||
args: []string{"replicationcontroller", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out, Local: false},
|
||||
},
|
||||
{
|
||||
object: &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "nginx",
|
||||
Image: "nginx",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"deployment", "nginx", "env=prod"},
|
||||
opts: &EnvOptions{Out: out,
|
||||
Local: false,
|
||||
From: "configmap/myconfigmap"},
|
||||
},
|
||||
{
|
||||
object: &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "nginx"},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "nginx",
|
||||
Image: "nginx",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
testAPIGroup: "extensions",
|
||||
apiPrefix: "/apis", apiGroup: "apps", apiVersion: "v1",
|
||||
args: []string{"deployment", "nginx"},
|
||||
opts: &EnvOptions{Out: out,
|
||||
Local: false,
|
||||
Keys: []string{"test-key"},
|
||||
From: "configmap/myconfigmap"},
|
||||
},
|
||||
}
|
||||
for _, input := range inputs {
|
||||
@@ -465,16 +531,16 @@ func TestSetEnvRemote(t *testing.T) {
|
||||
}),
|
||||
VersionedAPIPath: path.Join(input.apiPrefix, testapi.Default.GroupVersion().String()),
|
||||
}
|
||||
out := new(bytes.Buffer)
|
||||
cmd := NewCmdEnv(f, out, out, out)
|
||||
cmd.SetOutput(out)
|
||||
cmd.Flags().Set("output", "yaml")
|
||||
opts := EnvOptions{
|
||||
Out: out,
|
||||
Local: false}
|
||||
err := opts.Complete(f, cmd, input.args)
|
||||
opts := input.opts
|
||||
opts.Complete(f, cmd)
|
||||
err := opts.Validate(input.args)
|
||||
assert.NoError(t, err)
|
||||
err = opts.RunEnv(f)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
// TODO This global state restoration needs fixing, b/c it's wrong. Tests should not modify global state
|
||||
testapi.Default = testapi.Groups[""]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user