Skip to content

Commit

Permalink
truncating description fields preventing the manifest from being too …
Browse files Browse the repository at this point in the history
…long
  • Loading branch information
ayushsatyam146 committed Apr 23, 2024
1 parent 1000268 commit 49e8dc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions controllers/shipwrightbuild_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (r *ShipwrightBuildReconciler) Reconcile(ctx context.Context, req ctrl.Requ
images := common.ToLowerCaseKeys(common.ImagesFromEnv(common.ShipwrightImagePrefix))

transformerfncs := []manifestival.Transformer{}
transformerfncs = append(transformerfncs, common.TruncateDescription())
if common.IsOpenShiftPlatform() {
transformerfncs = append(transformerfncs, manifestival.InjectNamespace(targetNamespace))
transformerfncs = append(transformerfncs, common.DeploymentImages(images))
Expand Down
30 changes: 30 additions & 0 deletions pkg/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ func ToLowerCaseKeys(keyValues map[string]string) map[string]string {
return newMap
}

func removeDescriptionsRecursively(data map[string]interface{}) {
for key, value := range data {
if key == "description" {
delete(data, key)
continue
}
if subObj, ok := value.(map[string]interface{}); ok {
removeDescriptionsRecursively(subObj)
}
if subObjs, ok := value.([]interface{}); ok {
for _, subObj := range subObjs {
if subObjMap, ok := subObj.(map[string]interface{}); ok {
removeDescriptionsRecursively(subObjMap)
}
}
}
}
}

func TruncateDescription() manifestival.Transformer {
return func(u *unstructured.Unstructured) error {
if u.GetKind() != "CustomResourceDefinition" {
return nil
}
data := u.Object
removeDescriptionsRecursively(data)
return nil
}
}

// deploymentImages replaces container and env vars images.
func DeploymentImages(images map[string]string) manifestival.Transformer {
return func(u *unstructured.Unstructured) error {
Expand Down

0 comments on commit 49e8dc3

Please sign in to comment.