Skip to content

Commit 8005ec7

Browse files
authored
Correctly handle wrapped resources that use generateName (#194)
Fixes #193.
1 parent ce0595e commit 8005ec7

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

internal/controller/appwrapper/resource_management.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func (r *AppWrapperReconciler) createComponent(ctx context.Context, aw *workload
184184
}
185185
}
186186

187+
aw.Status.ComponentStatus[componentIdx].Name = obj.GetName() // Update name to support usage of GenerateName
187188
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
188189
Type: string(workloadv1beta2.ResourcesDeployed),
189190
Status: metav1.ConditionTrue,
@@ -210,7 +211,8 @@ func (r *AppWrapperReconciler) createComponents(ctx context.Context, aw *workloa
210211
func (r *AppWrapperReconciler) deleteComponents(ctx context.Context, aw *workloadv1beta2.AppWrapper) bool {
211212
deleteIfPresent := func(idx int, opts ...client.DeleteOption) bool {
212213
cs := &aw.Status.ComponentStatus[idx]
213-
if rd := meta.FindStatusCondition(cs.Conditions, string(workloadv1beta2.ResourcesDeployed)); rd == nil || rd.Status == metav1.ConditionFalse {
214+
rd := meta.FindStatusCondition(cs.Conditions, string(workloadv1beta2.ResourcesDeployed))
215+
if rd == nil || rd.Status == metav1.ConditionFalse || (rd.Status == metav1.ConditionUnknown && cs.Name == "") {
214216
return false // not present
215217
}
216218
obj := &metav1.PartialObjectMetadata{

test/e2e/fixtures_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ const batchJobYAML = `
208208
apiVersion: batch/v1
209209
kind: Job
210210
metadata:
211-
name: %v
211+
generateName: %v
212212
spec:
213213
template:
214214
spec:
@@ -225,7 +225,7 @@ spec:
225225

226226
func batchjob(milliCPU int64) workloadv1beta2.AppWrapperComponent {
227227
yamlString := fmt.Sprintf(batchJobYAML,
228-
randName("batchjob"),
228+
"batchjob-",
229229
resource.NewMilliQuantity(milliCPU, resource.DecimalSI))
230230

231231
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))
@@ -272,7 +272,7 @@ const succeedingBatchJobYAML = `
272272
apiVersion: batch/v1
273273
kind: Job
274274
metadata:
275-
name: %v
275+
generateName: %v
276276
spec:
277277
template:
278278
spec:
@@ -289,7 +289,7 @@ spec:
289289

290290
func succeedingBatchjob(milliCPU int64) workloadv1beta2.AppWrapperComponent {
291291
yamlString := fmt.Sprintf(succeedingBatchJobYAML,
292-
randName("batchjob"),
292+
"batchjob-",
293293
resource.NewMilliQuantity(milliCPU, resource.DecimalSI))
294294

295295
jsonBytes, err := yaml.YAMLToJSON([]byte(yamlString))

0 commit comments

Comments
 (0)