@@ -120,7 +120,7 @@ func TestKpt_Deploy(t *testing.T) {
120
120
AndRunOut (fmt .Sprintf ("kpt fn sink %v" , tmpKustomizeDir ), `` ).
121
121
AndRunOut (fmt .Sprintf ("kustomize build %v" , tmpKustomizeDir ), `` ).
122
122
AndRunOut ("kpt fn run --dry-run" , testPod ).
123
- AndRun ("kpt live apply valid_path" ),
123
+ AndRun ("kpt live apply valid_path --context kubecontext --namespace testNamespace " ),
124
124
expected : []string {"default" },
125
125
},
126
126
{
@@ -131,8 +131,8 @@ func TestKpt_Deploy(t *testing.T) {
131
131
commands : testutil .
132
132
CmdRunOut ("kpt fn source ." , `` ).
133
133
AndRunOut ("kpt fn run --dry-run" , testPod ).
134
- AndRunOut ("kpt live init .kpt-hydrated" , `` ).
135
- AndRunErr ("kpt live apply .kpt-hydrated" , errors .New ("BUG" )),
134
+ AndRunOut ("kpt live init .kpt-hydrated --context kubecontext --namespace testNamespace " , `` ).
135
+ AndRunErr ("kpt live apply .kpt-hydrated --context kubecontext --namespace testNamespace " , errors .New ("BUG" )),
136
136
shouldErr : true ,
137
137
},
138
138
{
@@ -152,7 +152,7 @@ func TestKpt_Deploy(t *testing.T) {
152
152
commands : testutil .
153
153
CmdRunOut ("kpt fn source ." , `` ).
154
154
AndRunOut ("kpt fn run --dry-run" , testPod ).
155
- AndRun ("kpt live apply valid_path --poll-period 5s --reconcile-timeout 2m" ),
155
+ AndRun ("kpt live apply valid_path --poll-period 5s --reconcile-timeout 2m --context kubecontext --namespace testNamespace " ),
156
156
},
157
157
{
158
158
description : "user specifies invalid reconcile timeout and poll period" ,
@@ -171,7 +171,7 @@ func TestKpt_Deploy(t *testing.T) {
171
171
commands : testutil .
172
172
CmdRunOut ("kpt fn source ." , `` ).
173
173
AndRunOut ("kpt fn run --dry-run" , testPod ).
174
- AndRun ("kpt live apply valid_path --poll-period foo --reconcile-timeout bar" ),
174
+ AndRun ("kpt live apply valid_path --poll-period foo --reconcile-timeout bar --context kubecontext --namespace testNamespace " ),
175
175
},
176
176
{
177
177
description : "user specifies prune propagation policy and prune timeout" ,
@@ -190,7 +190,7 @@ func TestKpt_Deploy(t *testing.T) {
190
190
commands : testutil .
191
191
CmdRunOut ("kpt fn source ." , `` ).
192
192
AndRunOut ("kpt fn run --dry-run" , testPod ).
193
- AndRun ("kpt live apply valid_path --prune-propagation-policy Orphan --prune-timeout 2m" ),
193
+ AndRun ("kpt live apply valid_path --prune-propagation-policy Orphan --prune-timeout 2m --context kubecontext --namespace testNamespace " ),
194
194
},
195
195
{
196
196
description : "user specifies invalid prune propagation policy and prune timeout" ,
@@ -209,7 +209,7 @@ func TestKpt_Deploy(t *testing.T) {
209
209
commands : testutil .
210
210
CmdRunOut ("kpt fn source ." , `` ).
211
211
AndRunOut ("kpt fn run --dry-run" , testPod ).
212
- AndRun ("kpt live apply valid_path --prune-propagation-policy foo --prune-timeout bar" ),
212
+ AndRun ("kpt live apply valid_path --prune-propagation-policy foo --prune-timeout bar --context kubecontext --namespace testNamespace " ),
213
213
},
214
214
}
215
215
for _ , test := range tests {
@@ -385,19 +385,19 @@ func TestKpt_Cleanup(t *testing.T) {
385
385
{
386
386
description : "valid user specified applyDir w/o template resource" ,
387
387
applyDir : "valid_path" ,
388
- commands : testutil .CmdRunErr ("kpt live destroy valid_path" , errors .New ("BUG" )),
388
+ commands : testutil .CmdRunErr ("kpt live destroy valid_path --context kubecontext --namespace testNamespace " , errors .New ("BUG" )),
389
389
shouldErr : true ,
390
390
},
391
391
{
392
392
description : "valid user specified applyDir w/ template resource (emulated)" ,
393
393
applyDir : "valid_path" ,
394
- commands : testutil .CmdRun ("kpt live destroy valid_path" ),
394
+ commands : testutil .CmdRun ("kpt live destroy valid_path --context kubecontext --namespace testNamespace " ),
395
395
},
396
396
{
397
397
description : "unspecified applyDir" ,
398
398
commands : testutil .
399
- CmdRunOut ("kpt live init .kpt-hydrated" , "" ).
400
- AndRun ("kpt live destroy .kpt-hydrated" ),
399
+ CmdRunOut ("kpt live init .kpt-hydrated --context kubecontext --namespace testNamespace " , "" ).
400
+ AndRun ("kpt live destroy .kpt-hydrated --context kubecontext --namespace testNamespace " ),
401
401
},
402
402
}
403
403
for _ , test := range tests {
@@ -808,7 +808,7 @@ func TestKpt_GetApplyDir(t *testing.T) {
808
808
{
809
809
description : "unspecified applyDir" ,
810
810
expected : ".kpt-hydrated" ,
811
- commands : testutil .CmdRunOut ("kpt live init .kpt-hydrated" , "" ),
811
+ commands : testutil .CmdRunOut ("kpt live init .kpt-hydrated --context kubecontext --namespace testNamespace " , "" ),
812
812
},
813
813
{
814
814
description : "unspecified applyDir with specified inventory-id and namespace" ,
@@ -819,7 +819,7 @@ func TestKpt_GetApplyDir(t *testing.T) {
819
819
},
820
820
},
821
821
expected : ".kpt-hydrated" ,
822
- commands : testutil .CmdRunOut ("kpt live init .kpt-hydrated --inventory-id 1a23bcde-4f56-7891-a2bc-de34fabcde5f6 --namespace foo" , "" ),
822
+ commands : testutil .CmdRunOut ("kpt live init .kpt-hydrated --inventory-id 1a23bcde-4f56-7891-a2bc-de34fabcde5f6 --context kubecontext -- namespace foo" , "" ),
823
823
},
824
824
{
825
825
description : "existing template resource in .kpt-hydrated" ,
@@ -1126,11 +1126,35 @@ func TestVersionCheck(t *testing.T) {
1126
1126
}
1127
1127
}
1128
1128
1129
+ func TestNonEmptyKubeconfig (t * testing.T ) {
1130
+ commands := testutil .CmdRunOut ("kpt fn source ." , `` ).
1131
+ AndRunOut ("kpt fn run --dry-run" , testPod ).
1132
+ AndRun ("kpt live apply valid_path --context kubecontext --kubeconfig testConfigPath --namespace testNamespace" )
1133
+
1134
+ testutil .Run (t , "" , func (t * testutil.T ) {
1135
+ t .Override (& util .DefaultExecCommand , commands )
1136
+ k := NewDeployer (& kptConfig {config : "testConfigPath" }, nil , & latestV1.KptDeploy {
1137
+ Dir : "." ,
1138
+ Live : latestV1.KptLive {
1139
+ Apply : latestV1.KptApplyInventory {
1140
+ Dir : "valid_path" ,
1141
+ },
1142
+ },
1143
+ })
1144
+ os .Mkdir (k .Live .Apply .Dir , 0755 )
1145
+ defer os .RemoveAll (k .Live .Apply .Dir )
1146
+ _ , err := k .Deploy (context .Background (), ioutil .Discard , []graph.Artifact {})
1147
+ t .CheckNoError (err )
1148
+ })
1149
+ }
1150
+
1129
1151
type kptConfig struct {
1130
1152
runcontext.RunContext // Embedded to provide the default values.
1131
1153
workingDir string
1154
+ config string
1132
1155
}
1133
1156
1134
1157
func (c * kptConfig ) WorkingDir () string { return c .workingDir }
1135
1158
func (c * kptConfig ) GetKubeContext () string { return kubectl .TestKubeContext }
1136
1159
func (c * kptConfig ) GetKubeNamespace () string { return kubectl .TestNamespace }
1160
+ func (c * kptConfig ) GetKubeConfig () string { return c .config }
0 commit comments