Skip to content

Commit

Permalink
Sort assets according to their creation order preference
Browse files Browse the repository at this point in the history
Make sure SAs and Roles are created before bindings, followed
by other resources like DS and Deployments.
  • Loading branch information
bertinatto committed Dec 12, 2023
1 parent 11cd893 commit 939f3df
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pkg/generated-assets/generated_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (a *CSIDriverAssets) GetControllerStaticAssetNames() []string {
klog.V(4).Infof("Added %s %s to controller static assets", kind, name)
names = append(names, name)
}
return names
return sortAssets(names)
}

// GetGuestStaticAssetNames returns the generated names of all static assets deployed in the guest cluster (or
Expand All @@ -117,7 +117,7 @@ func (a *CSIDriverAssets) GetGuestStaticAssetNames() []string {
klog.V(4).Infof("Added %s %s to guest static assets", kind, name)
names = append(names, name)
}
return names
return sortAssets(names)
}

// GetStorageClassAssetNames returns the names of all generated StorageClass assets.
Expand Down Expand Up @@ -275,3 +275,22 @@ func getYAMLKind(yaml []byte) (string, error) {
}
return gvk.GroupKind().String(), nil
}

func sortAssets(names []string) []string {
var stage1, stage2, stage3 []string
for i := range names {
switch {
case strings.HasSuffix(names[i], "_sa.yaml") || strings.HasSuffix(names[i], "_role.yaml"):
stage1 = append(stage1, names[i])
case strings.HasSuffix(names[i], "_binding.yaml"):
stage2 = append(stage2, names[i])
default:
stage3 = append(stage3, names[i])
}
}
result := make([]string, 0, len(names))
result = append(result, stage1...)
result = append(result, stage2...)
result = append(result, stage3...)
return result
}

0 comments on commit 939f3df

Please sign in to comment.