Skip to content

Commit

Permalink
fix sts pvc logic
Browse files Browse the repository at this point in the history
Co-authored-by: yelshall <[email protected]>
Signed-off-by: Julian Lawrence <[email protected]>
  • Loading branch information
jklaw90 and yelshall committed Sep 18, 2024
1 parent ec0521a commit 106eb02
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/resourceinterpreter/default/native/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,28 @@ func getStatefulSetDependencies(object *unstructured.Unstructured) ([]configv1al
return nil, err
}

return helper.GetDependenciesFromPodTemplate(podObj)
var validDeps []configv1alpha1.DependentObjectReference
deps, err := helper.GetDependenciesFromPodTemplate(podObj)
if err != nil {
return nil, err
}

// ignore the PersistentVolumeClaim dependency if it was created by the StatefulSet VolumeClaimTemplates
for _, dep := range deps {
if dep.Kind != "PersistentVolumeClaim" ||
len(statefulSetObj.Spec.VolumeClaimTemplates) == 0 {
validDeps = append(validDeps, dep)
continue
}
for _, volumeClaimTemplate := range statefulSetObj.Spec.VolumeClaimTemplates {
if dep.Name == volumeClaimTemplate.Name {
continue
}
validDeps = append(validDeps, dep)
}
}

return validDeps, nil
}

func getIngressDependencies(object *unstructured.Unstructured) ([]configv1alpha1.DependentObjectReference, error) {
Expand Down
33 changes: 33 additions & 0 deletions pkg/resourceinterpreter/default/native/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,39 @@ func Test_getStatefulSetDependencies(t *testing.T) {
want: testPairs[2].dependentObjectReference,
wantErr: false,
},
{
name: "statefulset with partial dependencies 4",
object: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"metadata": map[string]interface{}{
"name": "fake-statefulset",
"namespace": namespace,
},
"spec": map[string]interface{}{
"serviceName": "fake-service",
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "fake",
},
},
"template": map[string]interface{}{
"spec": testPairs[0].podSpecsWithDependencies.Object,
},
"volumeClaimTemplates": []interface{}{
map[string]interface{}{
"metadata": map[string]interface{}{
"name": "test-pvc",
},
},
},
},
},
},
want: testPairs[0].dependentObjectReference[:3], // remove the pvc dependency because it was found in the volumeClaimTemplates
wantErr: false,
},
}

for i := range tests {
Expand Down

0 comments on commit 106eb02

Please sign in to comment.