mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Document constants package.
This commit is contained in:
@@ -53,4 +53,10 @@ runTest testGoVet
|
||||
runTest testGoTest
|
||||
runTest testExamples
|
||||
|
||||
if [ $rc -eq 0 ]; then
|
||||
echo "SUCCESS!"
|
||||
else
|
||||
echo "FAILURE; exit code $rc"
|
||||
fi
|
||||
|
||||
exit $rc
|
||||
|
||||
@@ -61,7 +61,7 @@ func (mf *kustomizationFile) validate() error {
|
||||
}
|
||||
} else {
|
||||
if !strings.HasSuffix(mf.path, constants.KustomizationFileName) {
|
||||
errorMsg := fmt.Sprintf("Kustomization file path (%s) should have %s suffix\n", mf.path, constants.KustomizationSuffix)
|
||||
errorMsg := fmt.Sprintf("Kustomization file path (%s) should have %s suffix\n", mf.path, constants.KustomizationFileSuffix)
|
||||
merr := interror.KustomizationError{KustomizationPath: mf.path, ErrorMsg: errorMsg}
|
||||
return merr
|
||||
}
|
||||
|
||||
@@ -14,14 +14,11 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package constants holds global constants for the kustomize tool.
|
||||
package constants
|
||||
|
||||
const KustomizationSuffix = ".yaml"
|
||||
// KustomizationFileSuffix is expected suffix for KustomizationFileName.
|
||||
const KustomizationFileSuffix = ".yaml"
|
||||
|
||||
// KustomizationFileName is the Well-Known File Name for a kustomize configuration file.
|
||||
const KustomizationFileName = "kustomization" + KustomizationSuffix
|
||||
|
||||
// Configmap behaviors
|
||||
const CreateBehavior = "create"
|
||||
const ReplaceBehavior = "replace"
|
||||
const MergeBehavior = "merge"
|
||||
const KustomizationFileName = "kustomization" + KustomizationFileSuffix
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/kubernetes-sigs/kustomize/pkg/constants"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
|
||||
)
|
||||
@@ -94,8 +93,13 @@ func Merge(rcs ...ResourceCollection) (ResourceCollection, error) {
|
||||
return all, nil
|
||||
}
|
||||
|
||||
// MergeWithOverride will merge all of the entries in the slice of ResourceCollection with Override
|
||||
// If there is already an entry with the same GVKN exists, different actions are performed according to value of Behavior field
|
||||
const behaviorCreate = "create"
|
||||
const behaviorReplace = "replace"
|
||||
const behaviorMerge = "merge"
|
||||
|
||||
// MergeWithOverride merges the entries in the ResourceCollection slice with Override.
|
||||
// If there is already an entry with the same GVKN , different actions are performed
|
||||
// according to value of Behavior field:
|
||||
// 'create': create a new one;
|
||||
// 'replace': replace the data only; keep the labels and annotations
|
||||
// 'merge': merge the data; keep the labels and annotations
|
||||
@@ -106,13 +110,13 @@ func MergeWithOverride(rcs ...ResourceCollection) (ResourceCollection, error) {
|
||||
for gvkn, obj := range rc {
|
||||
if _, found := all[gvkn]; found {
|
||||
switch obj.Behavior {
|
||||
case "", constants.CreateBehavior:
|
||||
case "", behaviorCreate:
|
||||
return nil, fmt.Errorf("Create an existing gvkn %#v is not allowed", gvkn)
|
||||
case constants.ReplaceBehavior:
|
||||
case behaviorReplace:
|
||||
glog.V(4).Infof("Replace object %v by %v", all[gvkn].Data.Object, obj.Data.Object)
|
||||
obj.replace(all[gvkn])
|
||||
all[gvkn] = obj
|
||||
case constants.MergeBehavior:
|
||||
case behaviorMerge:
|
||||
glog.V(4).Infof("Merge object %v with %v", all[gvkn].Data.Object, obj.Data.Object)
|
||||
obj.merge(all[gvkn])
|
||||
all[gvkn] = obj
|
||||
@@ -122,9 +126,9 @@ func MergeWithOverride(rcs ...ResourceCollection) (ResourceCollection, error) {
|
||||
}
|
||||
} else {
|
||||
switch obj.Behavior {
|
||||
case "", constants.CreateBehavior:
|
||||
case "", behaviorCreate:
|
||||
all[gvkn] = obj
|
||||
case constants.MergeBehavior, constants.ReplaceBehavior:
|
||||
case behaviorMerge, behaviorReplace:
|
||||
return nil, fmt.Errorf("No merge or replace is allowed for non existing gvkn %#v", gvkn)
|
||||
default:
|
||||
return nil, fmt.Errorf("The behavior of %#v must be create since it doesn't exist", gvkn)
|
||||
|
||||
Reference in New Issue
Block a user