github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/kubernetes/manifest/transformations.go (about)

     1  /*
     2  Copyright 2019 The Skaffold Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package manifest
    18  
    19  import (
    20  	"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
    21  )
    22  
    23  type Registries struct {
    24  	InsecureRegistries   map[string]bool
    25  	DebugHelpersRegistry string
    26  }
    27  
    28  type Transform func(l ManifestList, builds []graph.Artifact, registries Registries) (ManifestList, error)
    29  
    30  // Transforms are applied to manifests
    31  var transforms []Transform
    32  
    33  // AddTransform adds a transform to be applied when deploying.
    34  func AddTransform(newTransform Transform) {
    35  	transforms = append(transforms, newTransform)
    36  }
    37  
    38  // GetTransforms returns all manifest transforms.
    39  func GetTransforms() []Transform {
    40  	return transforms
    41  }
    42  
    43  // ApplyTransforms applies all manifests transforms to the provided manifests.
    44  func ApplyTransforms(manifests ManifestList, builds []graph.Artifact, insecureRegistries map[string]bool, debugHelpersRegistry string) (ManifestList, error) {
    45  	var err error
    46  	for _, transform := range transforms {
    47  		manifests, err = transform(manifests, builds, Registries{insecureRegistries, debugHelpersRegistry})
    48  		if err != nil {
    49  			return nil, transformManifestErr(err)
    50  		}
    51  	}
    52  	return manifests, nil
    53  }