diff --git a/cmd/kustomize/demos/helloWorld.md b/cmd/kustomize/demos/helloWorld.md index d6e9c5bf5..63a02513a 100644 --- a/cmd/kustomize/demos/helloWorld.md +++ b/cmd/kustomize/demos/helloWorld.md @@ -133,10 +133,7 @@ defining a new name prefix, and some different labels. ``` cat <<'EOF' >$OVERLAYS/staging/kustomize.yaml -apiVersion: manifest.k8s.io/v1alpha1 -kind: Package -metadata: - name: makes-staging-hello +kustomizationName: makes-staging-hello namePrefix: staging- objectLabels: instance: staging @@ -178,10 +175,7 @@ with a different name prefix and labels. ``` cat <$OVERLAYS/production/kustomize.yaml -apiVersion: manifest.k8s.io/v1alpha1 -kind: Package -metadata: - name: makes-production-tuthello +kustomizationName: makes-production-tuthello namePrefix: production- objectLabels: instance: production diff --git a/pkg/apis/manifest/v1alpha1/doc.go b/pkg/apis/manifest/v1alpha1/doc.go deleted file mode 100644 index e29c330f2..000000000 --- a/pkg/apis/manifest/v1alpha1/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package v1alpha1 contains the type definition for Manifest and Descriptor. -// It is not an official kubernetes API, but in a kubernetes API style. -package v1alpha1 // import "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" diff --git a/pkg/kustomize/app/application.go b/pkg/kustomize/app/application.go index 586d257fe..a087efb57 100644 --- a/pkg/kustomize/app/application.go +++ b/pkg/kustomize/app/application.go @@ -22,11 +22,11 @@ import ( "github.com/ghodss/yaml" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" "k8s.io/kubectl/pkg/kustomize/constants" interror "k8s.io/kubectl/pkg/kustomize/internal/error" "k8s.io/kubectl/pkg/kustomize/resource" "k8s.io/kubectl/pkg/kustomize/transformers" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/loader" ) @@ -35,8 +35,10 @@ type Application interface { Resources() (resource.ResourceCollection, error) // SemiResources computes and returns the resources without name hash and name reference for the app SemiResources() (resource.ResourceCollection, error) - // RawResources computes and returns the raw resources from the manifest. - // It contains resources from 1) untransformed resources from current manifest 2) transformed resources from sub packages + // RawResources computes and returns the raw resources from the kustomize config file. + // It contains resources from + // 1) untransformed resources from current kustomize config file + // 2) transformed resources from sub packages RawResources() (resource.ResourceCollection, error) } @@ -44,19 +46,19 @@ var _ Application = &applicationImpl{} // Private implementation of the Application interface type applicationImpl struct { - manifest *manifest.Manifest + manifest *types.Manifest loader loader.Loader } -// NewApp parses the manifest at the path using the loader. +// NewApp parses the kustomize config file at the path using the loader. func New(loader loader.Loader) (Application, error) { - // load the manifest using the loader + // load the kustomize config file using the loader manifestBytes, err := loader.Load(constants.KustomizeFileName) if err != nil { return nil, err } - var m manifest.Manifest + var m types.Manifest err = unmarshal(manifestBytes, &m) if err != nil { return nil, err @@ -64,7 +66,7 @@ func New(loader loader.Loader) (Application, error) { return &applicationImpl{manifest: &m, loader: loader}, nil } -// Resources computes and returns the resources from the manifest. +// Resources computes and returns the resources from the kustomize config file. // The namehashing for configmap/secrets and resolving name reference is only done // in the most top overlay once at the end of getting resources. func (a *applicationImpl) Resources() (resource.ResourceCollection, error) { @@ -130,7 +132,7 @@ func (a *applicationImpl) SemiResources() (resource.ResourceCollection, error) { return allRes, nil } -// RawResources computes and returns the raw resources from the manifest. +// RawResources computes and returns the raw resources from the kustomize config file. // The namehashing for configmap/secrets and resolving name reference is only done // in the most top overlay once at the end of getting resources. func (a *applicationImpl) RawResources() (resource.ResourceCollection, error) { diff --git a/pkg/kustomize/app/application_test.go b/pkg/kustomize/app/application_test.go index 3a49b923b..cc78748ae 100644 --- a/pkg/kustomize/app/application_test.go +++ b/pkg/kustomize/app/application_test.go @@ -32,10 +32,7 @@ import ( ) func setupTest(t *testing.T) loader.Loader { - manifestContent := []byte(`apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app + manifestContent := []byte(`kustomizationName: nginx-app namePrefix: foo- objectLabels: app: nginx diff --git a/pkg/kustomize/commands/configmap.go b/pkg/kustomize/commands/configmap.go index 127adbc9c..7d79c46b7 100644 --- a/pkg/kustomize/commands/configmap.go +++ b/pkg/kustomize/commands/configmap.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" "k8s.io/kubectl/pkg/kustomize/configmapandsecret" "k8s.io/kubectl/pkg/kustomize/constants" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/kustomize/util/fs" ) @@ -32,13 +32,13 @@ func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command { var config dataConfig cmd := &cobra.Command{ Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1]", - Short: "Adds a configmap to the manifest.", + Short: "Adds a configmap to the kustomize config file.", Long: "", Example: ` - # Adds a configmap to the Manifest (with a specified key) + # Adds a configmap to the kustomize config file (with a specified key) kustomize edit add configmap my-configmap --from-file=my-key=file/path --from-literal=my-literal=12345 - # Adds a configmap to the Manifest (key is the filename) + # Adds a configmap to the kustomize config file (key is the filename) kustomize edit add configmap my-configmap --from-file=file/path # Adds a configmap from env-file @@ -50,7 +50,7 @@ func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command { return err } - // Load in the manifest file. + // Load in the kustomize config file. mf, err := newManifestFile(constants.KustomizeFileName, fsys) if err != nil { return err @@ -61,13 +61,13 @@ func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command { return err } - // Add the config map to the manifest. + // Add the config map to the kustomize config file. err = addConfigMap(m, config) if err != nil { return err } - // Write out the manifest with added configmap. + // Write out the kustomize config file with added configmap. return mf.write(m) }, } @@ -79,10 +79,10 @@ func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command { return cmd } -// addConfigMap updates a configmap within a manifest, using the data in config. -// Note: error may leave manifest in an undefined state. Suggest passing a copy -// of manifest. -func addConfigMap(m *manifest.Manifest, config dataConfig) error { +// addConfigMap updates a configmap within a kustomize config file, using the data in config. +// Note: error may leave kustomize config file in an undefined state. Suggest passing a copy +// of kustomize config file. +func addConfigMap(m *types.Manifest, config dataConfig) error { cm := getOrCreateConfigMap(m, config.Name) err := mergeData(&cm.DataSources, config) @@ -90,7 +90,7 @@ func addConfigMap(m *manifest.Manifest, config dataConfig) error { return err } - // Validate manifest's configmap by trying to create corev1.configmap. + // Validate by trying to create corev1.configmap. _, _, err = configmapandsecret.MakeConfigmapAndGenerateName(*cm) if err != nil { return err @@ -99,19 +99,19 @@ func addConfigMap(m *manifest.Manifest, config dataConfig) error { return nil } -func getOrCreateConfigMap(m *manifest.Manifest, name string) *manifest.ConfigMapArgs { +func getOrCreateConfigMap(m *types.Manifest, name string) *types.ConfigMapArgs { for i, v := range m.ConfigMapGenerator { if name == v.Name { return &m.ConfigMapGenerator[i] } } - // config map not found, create new one and add it to the manifest. - cm := &manifest.ConfigMapArgs{Name: name} + // config map not found, create new one and add it to the kustomize config file. + cm := &types.ConfigMapArgs{Name: name} m.ConfigMapGenerator = append(m.ConfigMapGenerator, *cm) return &m.ConfigMapGenerator[len(m.ConfigMapGenerator)-1] } -func mergeData(src *manifest.DataSources, config dataConfig) error { +func mergeData(src *types.DataSources, config dataConfig) error { src.LiteralSources = append(src.LiteralSources, config.LiteralSources...) src.FileSources = append(src.FileSources, config.FileSources...) if src.EnvSource != "" && src.EnvSource != config.EnvFileSource { diff --git a/pkg/kustomize/commands/configmap_test.go b/pkg/kustomize/commands/configmap_test.go index 473c3982c..944724b03 100644 --- a/pkg/kustomize/commands/configmap_test.go +++ b/pkg/kustomize/commands/configmap_test.go @@ -19,7 +19,7 @@ package commands import ( "testing" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/kustomize/util/fs" ) @@ -32,7 +32,7 @@ func TestNewAddConfigMapIsNotNil(t *testing.T) { func TestGetOrCreateConfigMap(t *testing.T) { cmName := "test-config-name" - manifest := &manifest.Manifest{ + manifest := &types.Manifest{ NamePrefix: "test-name-prefix", } @@ -65,7 +65,7 @@ func TestGetOrCreateConfigMap(t *testing.T) { } func TestMergeData_LiteralSources(t *testing.T) { - ds := &manifest.DataSources{} + ds := &types.DataSources{} err := mergeData(ds, dataConfig{LiteralSources: []string{"k1=v1"}}) if err != nil { @@ -87,7 +87,7 @@ func TestMergeData_LiteralSources(t *testing.T) { } func TestMergeData_FileSources(t *testing.T) { - ds := &manifest.DataSources{} + ds := &types.DataSources{} err := mergeData(ds, dataConfig{FileSources: []string{"file1"}}) if err != nil { @@ -111,7 +111,7 @@ func TestMergeData_FileSources(t *testing.T) { func TestMergeData_EnvSource(t *testing.T) { envFileName := "env1" envFileName2 := "env2" - ds := &manifest.DataSources{} + ds := &types.DataSources{} err := mergeData(ds, dataConfig{EnvFileSource: envFileName}) if err != nil { diff --git a/pkg/kustomize/commands/testdata/testcase-base-only/in/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-base-only/in/kustomize.yaml index bfd9e811e..b351764f0 100644 --- a/pkg/kustomize/commands/testdata/testcase-base-only/in/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-base-only/in/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: team-foo- objectLabels: app: mynginx diff --git a/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml index ecb0ef4d4..2557dbe03 100644 --- a/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: staging- objectLabels: env: staging diff --git a/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml index e5e3ca206..be7bbb465 100644 --- a/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: team-foo- objectLabels: app: mynginx diff --git a/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml index 62e51a805..f628cd289 100644 --- a/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: staging- objectLabels: env: staging diff --git a/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml index e5e3ca206..be7bbb465 100644 --- a/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: team-foo- objectLabels: app: mynginx diff --git a/pkg/kustomize/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml index 765e47bff..409e23dc5 100644 --- a/pkg/kustomize/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: staging- objectLabels: env: staging diff --git a/pkg/kustomize/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml b/pkg/kustomize/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml index fb0bf362c..4df640854 100644 --- a/pkg/kustomize/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml +++ b/pkg/kustomize/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml @@ -1,7 +1,4 @@ -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: nginx-app +kustomizationName: nginx-app namePrefix: team-foo- objectLabels: app: mynginx diff --git a/pkg/kustomize/commands/util.go b/pkg/kustomize/commands/util.go index fb035b87b..cb60749fc 100644 --- a/pkg/kustomize/commands/util.go +++ b/pkg/kustomize/commands/util.go @@ -24,9 +24,9 @@ import ( "github.com/ghodss/yaml" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" "k8s.io/kubectl/pkg/kustomize/constants" interror "k8s.io/kubectl/pkg/kustomize/internal/error" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/kustomize/util/fs" ) @@ -47,7 +47,7 @@ func newManifestFile(mPath string, fsys fs.FileSystem) (*manifestFile, error) { func (mf *manifestFile) validate() error { f, err := mf.fsys.Stat(mf.mPath) if err != nil { - errorMsg := fmt.Sprintf("Manifest (%s) missing\nRun `kustomize init` first", mf.mPath) + errorMsg := fmt.Sprintf("Missing kustomize config file '%s'.\n", mf.mPath) merr := interror.ManifestError{ManifestFilepath: mf.mPath, ErrorMsg: errorMsg} return merr } @@ -55,13 +55,13 @@ func (mf *manifestFile) validate() error { mf.mPath = path.Join(mf.mPath, constants.KustomizeFileName) _, err = mf.fsys.Stat(mf.mPath) if err != nil { - errorMsg := fmt.Sprintf("Manifest (%s) missing\nRun `kustomize init` first", mf.mPath) + errorMsg := fmt.Sprintf("Missing kustomize config file '%s'.\n", mf.mPath) merr := interror.ManifestError{ManifestFilepath: mf.mPath, ErrorMsg: errorMsg} return merr } } else { if !strings.HasSuffix(mf.mPath, constants.KustomizeFileName) { - errorMsg := fmt.Sprintf("Manifest file (%s) should have %s suffix\n", mf.mPath, constants.KustomizeSuffix) + errorMsg := fmt.Sprintf("Kustomize config file path (%s) should have %s suffix\n", mf.mPath, constants.KustomizeSuffix) merr := interror.ManifestError{ManifestFilepath: mf.mPath, ErrorMsg: errorMsg} return merr } @@ -69,12 +69,12 @@ func (mf *manifestFile) validate() error { return nil } -func (mf *manifestFile) read() (*manifest.Manifest, error) { +func (mf *manifestFile) read() (*types.Manifest, error) { bytes, err := mf.fsys.ReadFile(mf.mPath) if err != nil { return nil, err } - var manifest manifest.Manifest + var manifest types.Manifest err = yaml.Unmarshal(bytes, &manifest) if err != nil { return nil, err @@ -82,9 +82,9 @@ func (mf *manifestFile) read() (*manifest.Manifest, error) { return &manifest, err } -func (mf *manifestFile) write(manifest *manifest.Manifest) error { +func (mf *manifestFile) write(manifest *types.Manifest) error { if manifest == nil { - return errors.New("util: failed to write passed-in nil manifest") + return errors.New("util: kustomize config file arg is nil.") } bytes, err := yaml.Marshal(manifest) if err != nil { diff --git a/pkg/kustomize/commands/util_test.go b/pkg/kustomize/commands/util_test.go index 696d77da9..f0c137470 100644 --- a/pkg/kustomize/commands/util_test.go +++ b/pkg/kustomize/commands/util_test.go @@ -21,12 +21,12 @@ import ( "strings" "testing" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/kustomize/util/fs" ) func TestWriteAndRead(t *testing.T) { - manifest := &manifest.Manifest{ + manifest := &types.Manifest{ NamePrefix: "prefix", } @@ -67,21 +67,23 @@ func TestNewNotExist(t *testing.T) { if err == nil { t.Fatalf("expect an error") } - if !strings.Contains(err.Error(), "Run `kustomize init` first") { - t.Fatalf("expect an error contains %q, but got %v", "does not exist", err) + contained := "Missing kustomize config file" + if !strings.Contains(err.Error(), contained) { + t.Fatalf("expect an error contains %q, but got %v", contained, err) } _, err = newManifestFile("kustomize.yaml", fakeFS) if err == nil { t.Fatalf("expect an error") } - if !strings.Contains(err.Error(), "Run `kustomize init` first") { - t.Fatalf("expect an error contains %q, but got %v", "does not exist", err) + if !strings.Contains(err.Error(), contained) { + t.Fatalf("expect an error contains %q, but got %v", contained, err) } _, err = newManifestFile(badSuffix, fakeFS) if err == nil { t.Fatalf("expect an error") } - if !strings.Contains(err.Error(), "should have .yaml suffix") { - t.Fatalf("expect an error contains %q, but got %v", "does not exist", err) + contained = "should have .yaml suffix" + if !strings.Contains(err.Error(), contained) { + t.Fatalf("expect an error contains %q, but got %v", contained, err) } } diff --git a/pkg/kustomize/configmapandsecret/configmap_secret.go b/pkg/kustomize/configmapandsecret/configmap_secret.go index d7087e0d9..72f0090ff 100644 --- a/pkg/kustomize/configmapandsecret/configmap_secret.go +++ b/pkg/kustomize/configmapandsecret/configmap_secret.go @@ -28,7 +28,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" cutil "k8s.io/kubectl/pkg/kustomize/configmapandsecret/util" "k8s.io/kubectl/pkg/kustomize/hash" "k8s.io/kubectl/pkg/kustomize/resource" @@ -36,7 +35,7 @@ import ( ) // MakeConfigmapAndGenerateName makes a configmap and returns the configmap and the name appended with a hash. -func MakeConfigmapAndGenerateName(cm manifest.ConfigMapArgs) (*unstructured.Unstructured, string, error) { +func MakeConfigmapAndGenerateName(cm types.ConfigMapArgs) (*unstructured.Unstructured, string, error) { corev1CM, err := makeConfigMap(cm) if err != nil { return nil, "", err @@ -51,7 +50,7 @@ func MakeConfigmapAndGenerateName(cm manifest.ConfigMapArgs) (*unstructured.Unst } // MakeSecretAndGenerateName returns a secret with the name appended with a hash. -func MakeSecretAndGenerateName(secret manifest.SecretArgs, path string) (*unstructured.Unstructured, string, error) { +func MakeSecretAndGenerateName(secret types.SecretArgs, path string) (*unstructured.Unstructured, string, error) { corev1Secret, err := makeSecret(secret, path) if err != nil { return nil, "", err @@ -75,7 +74,7 @@ func objectToUnstructured(in runtime.Object) (*unstructured.Unstructured, error) return &out, err } -func makeConfigMap(cm manifest.ConfigMapArgs) (*corev1.ConfigMap, error) { +func makeConfigMap(cm types.ConfigMapArgs) (*corev1.ConfigMap, error) { corev1cm := &corev1.ConfigMap{} corev1cm.APIVersion = "v1" corev1cm.Kind = "ConfigMap" @@ -101,7 +100,7 @@ func makeConfigMap(cm manifest.ConfigMapArgs) (*corev1.ConfigMap, error) { return corev1cm, nil } -func makeSecret(secret manifest.SecretArgs, path string) (*corev1.Secret, error) { +func makeSecret(secret types.SecretArgs, path string) (*corev1.Secret, error) { corev1secret := &corev1.Secret{} corev1secret.APIVersion = "v1" corev1secret.Kind = "Secret" @@ -137,7 +136,7 @@ func populateMap(m resource.ResourceCollection, obj *unstructured.Unstructured, } // MakeConfigMapsResourceCollection returns a map of -> unstructured object. -func MakeConfigMapsResourceCollection(maps []manifest.ConfigMapArgs) (resource.ResourceCollection, error) { +func MakeConfigMapsResourceCollection(maps []types.ConfigMapArgs) (resource.ResourceCollection, error) { m := resource.ResourceCollection{} for _, cm := range maps { unstructuredConfigMap, nameWithHash, err := MakeConfigmapAndGenerateName(cm) @@ -153,7 +152,7 @@ func MakeConfigMapsResourceCollection(maps []manifest.ConfigMapArgs) (resource.R } // MakeSecretsResourceCollection returns a map of -> unstructured object. -func MakeSecretsResourceCollection(secrets []manifest.SecretArgs, path string) (resource.ResourceCollection, error) { +func MakeSecretsResourceCollection(secrets []types.SecretArgs, path string) (resource.ResourceCollection, error) { m := resource.ResourceCollection{} for _, secret := range secrets { unstructuredSecret, nameWithHash, err := MakeSecretAndGenerateName(secret, path) diff --git a/pkg/kustomize/configmapandsecret/configmap_secret_test.go b/pkg/kustomize/configmapandsecret/configmap_secret_test.go index 7665ab8b9..628badf96 100644 --- a/pkg/kustomize/configmapandsecret/configmap_secret_test.go +++ b/pkg/kustomize/configmapandsecret/configmap_secret_test.go @@ -24,7 +24,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" + "k8s.io/kubectl/pkg/kustomize/types" ) func makeEnvConfigMap(name string) *corev1.ConfigMap { @@ -131,16 +131,16 @@ func makeUnstructuredSecret(name string) *unstructured.Unstructured { func TestConstructConfigMap(t *testing.T) { type testCase struct { description string - input manifest.ConfigMapArgs + input types.ConfigMapArgs expected *corev1.ConfigMap } testCases := []testCase{ { description: "construct config map from env", - input: manifest.ConfigMapArgs{ + input: types.ConfigMapArgs{ Name: "envConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ EnvSource: "../examples/simple/instances/exampleinstance/configmap/app.env", }, }, @@ -148,9 +148,9 @@ func TestConstructConfigMap(t *testing.T) { }, { description: "construct config map from file", - input: manifest.ConfigMapArgs{ + input: types.ConfigMapArgs{ Name: "fileConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ FileSources: []string{"../examples/simple/instances/exampleinstance/configmap/app-init.ini"}, }, }, @@ -158,9 +158,9 @@ func TestConstructConfigMap(t *testing.T) { }, { description: "construct config map from literal", - input: manifest.ConfigMapArgs{ + input: types.ConfigMapArgs{ Name: "literalConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ LiteralSources: []string{"a=x", "b=y"}, }, }, @@ -180,7 +180,7 @@ func TestConstructConfigMap(t *testing.T) { } func TestConstructSecret(t *testing.T) { - secret := manifest.SecretArgs{ + secret := types.SecretArgs{ Name: "secret", Commands: map[string]string{ "DB_USERNAME": "printf admin", @@ -199,7 +199,7 @@ func TestConstructSecret(t *testing.T) { } func TestFailConstructSecret(t *testing.T) { - secret := manifest.SecretArgs{ + secret := types.SecretArgs{ Name: "secret", Commands: map[string]string{ "FAILURE": "false", // This will fail. diff --git a/pkg/kustomize/examples/simple/instances/exampleinstance/kustomize.yaml b/pkg/kustomize/examples/simple/instances/exampleinstance/kustomize.yaml index c9892e080..1b7bd36ce 100644 --- a/pkg/kustomize/examples/simple/instances/exampleinstance/kustomize.yaml +++ b/pkg/kustomize/examples/simple/instances/exampleinstance/kustomize.yaml @@ -1,9 +1,4 @@ -# This example is from https://docs.google.com/document/d/1cLPGweVEYrVqQvBLJg6sxV-TrE5Rm2MNOBA_cxZP2WU/edit#heading=h.dr88tktf0e99 - -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: test-infra-mungebot +kustomizationName: test-infra-mungebot namePrefix: test-infra- # Labels to add to all objects and selectors. # These labels would also be used to form the selector for apply --prune diff --git a/pkg/kustomize/examples/simple/package/kustomize.yaml b/pkg/kustomize/examples/simple/package/kustomize.yaml index e5ab6d507..aeab828e3 100644 --- a/pkg/kustomize/examples/simple/package/kustomize.yaml +++ b/pkg/kustomize/examples/simple/package/kustomize.yaml @@ -1,11 +1,4 @@ -# This example is from https://docs.google.com/document/d/1cLPGweVEYrVqQvBLJg6sxV-TrE5Rm2MNOBA_cxZP2WU/edit#heading=h.dr88tktf0e99 - -# Inspired by https://github.com/kubernetes/helm/blob/master/docs/charts.md -# But Kubernetes API style -apiVersion: manifest.k8s.io/v1alpha1 -kind: Manifest -metadata: - name: mungebot +kustomizationName: mungebot namePrefix: baseprefix- # Labels to add to all objects and selectors. # These labels would also be used to form the selector for apply --prune diff --git a/pkg/kustomize/resource/configmap.go b/pkg/kustomize/resource/configmap.go index 53d00da10..bac33b431 100644 --- a/pkg/kustomize/resource/configmap.go +++ b/pkg/kustomize/resource/configmap.go @@ -22,12 +22,12 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/validation" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" cutil "k8s.io/kubectl/pkg/kustomize/configmapandsecret/util" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/loader" ) -func newFromConfigMap(l loader.Loader, cm manifest.ConfigMapArgs) (*Resource, error) { +func newFromConfigMap(l loader.Loader, cm types.ConfigMapArgs) (*Resource, error) { corev1CM, err := makeConfigMap(l, cm) if err != nil { return nil, err @@ -40,7 +40,7 @@ func newFromConfigMap(l loader.Loader, cm manifest.ConfigMapArgs) (*Resource, er return &Resource{Data: data, Behavior: cm.Behavior}, nil } -func makeConfigMap(l loader.Loader, cm manifest.ConfigMapArgs) (*corev1.ConfigMap, error) { +func makeConfigMap(l loader.Loader, cm types.ConfigMapArgs) (*corev1.ConfigMap, error) { var envPairs, literalPairs, filePairs []kvPair var err error @@ -130,8 +130,8 @@ func addKV(m map[string]string, kv kvPair) error { return nil } -// NewFromConfigMaps returns a Resource slice given a configmap metadata slice from manifest file. -func NewFromConfigMaps(loader loader.Loader, cmList []manifest.ConfigMapArgs) (ResourceCollection, error) { +// NewFromConfigMaps returns a Resource slice given a configmap metadata slice from kustomize config file. +func NewFromConfigMaps(loader loader.Loader, cmList []types.ConfigMapArgs) (ResourceCollection, error) { allResources := []*Resource{} for _, cm := range cmList { res, err := newFromConfigMap(loader, cm) diff --git a/pkg/kustomize/resource/configmap_test.go b/pkg/kustomize/resource/configmap_test.go index 4fbc53480..2528cad6e 100644 --- a/pkg/kustomize/resource/configmap_test.go +++ b/pkg/kustomize/resource/configmap_test.go @@ -22,15 +22,15 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" "k8s.io/kubectl/pkg/kustomize/resource" + "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/loader/loadertest" ) func TestNewFromConfigMaps(t *testing.T) { type testCase struct { description string - input []manifest.ConfigMapArgs + input []types.ConfigMapArgs filepath string content string expected resource.ResourceCollection @@ -40,10 +40,10 @@ func TestNewFromConfigMaps(t *testing.T) { testCases := []testCase{ { description: "construct config map from env", - input: []manifest.ConfigMapArgs{ + input: []types.ConfigMapArgs{ { Name: "envConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ EnvSource: "app.env", }, }, @@ -74,9 +74,9 @@ func TestNewFromConfigMaps(t *testing.T) { }, { description: "construct config map from file", - input: []manifest.ConfigMapArgs{{ + input: []types.ConfigMapArgs{{ Name: "fileConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ FileSources: []string{"app-init.ini"}, }, }, @@ -108,10 +108,10 @@ BAR=baz }, { description: "construct config map from literal", - input: []manifest.ConfigMapArgs{ + input: []types.ConfigMapArgs{ { Name: "literalConfigMap", - DataSources: manifest.DataSources{ + DataSources: types.DataSources{ LiteralSources: []string{"a=x", "b=y"}, }, }, diff --git a/pkg/kustomize/resource/secret.go b/pkg/kustomize/resource/secret.go index f97229751..b76c1784a 100644 --- a/pkg/kustomize/resource/secret.go +++ b/pkg/kustomize/resource/secret.go @@ -24,10 +24,10 @@ import ( "time" corev1 "k8s.io/api/core/v1" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" + "k8s.io/kubectl/pkg/kustomize/types" ) -func newFromSecretGenerator(p string, s manifest.SecretArgs) (*Resource, error) { +func newFromSecretGenerator(p string, s types.SecretArgs) (*Resource, error) { corev1secret := &corev1.Secret{} corev1secret.APIVersion = "v1" corev1secret.Kind = "Secret" @@ -70,7 +70,7 @@ func createSecretKey(wd string, command string) ([]byte, error) { // NewFromSecretGenerators takes a SecretGenerator slice and executes its command in directory p // then writes the output to a Resource slice and return it. -func NewFromSecretGenerators(p string, secretList []manifest.SecretArgs) (ResourceCollection, error) { +func NewFromSecretGenerators(p string, secretList []types.SecretArgs) (ResourceCollection, error) { allResources := []*Resource{} for _, secret := range secretList { res, err := newFromSecretGenerator(p, secret) diff --git a/pkg/kustomize/resource/secret_test.go b/pkg/kustomize/resource/secret_test.go index 50b8b001a..1b71848c1 100644 --- a/pkg/kustomize/resource/secret_test.go +++ b/pkg/kustomize/resource/secret_test.go @@ -24,11 +24,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" - manifest "k8s.io/kubectl/pkg/apis/manifest/v1alpha1" + "k8s.io/kubectl/pkg/kustomize/types" ) func TestNewFromSecretGenerators(t *testing.T) { - secrets := []manifest.SecretArgs{ + secrets := []types.SecretArgs{ { Name: "secret", Commands: map[string]string{ diff --git a/pkg/apis/manifest/v1alpha1/types.go b/pkg/kustomize/types/manifest.go similarity index 73% rename from pkg/apis/manifest/v1alpha1/types.go rename to pkg/kustomize/types/manifest.go index f6527844c..21b5ee068 100644 --- a/pkg/apis/manifest/v1alpha1/types.go +++ b/pkg/kustomize/types/manifest.go @@ -14,60 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// Descriptor contains all the metadata of the package and drives package -// searching and browsing, and support the fork/rebase upgrade workflow. -// It can be used by something like an app registry. -type Descriptor struct { - metav1.TypeMeta `json:",inline" yaml:",inline"` - // Standard object's metadata. - // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata - metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"` - - // The name of the package. - // The name of an individual instance should live in metadata.name. - Name string `json:"name,omitempty" yaml:"name,omitempty"` - - // Description of the package. - Description string `json:"description,omitempty" yaml:"description,omitempty"` - - // An pointer to the icon. - Icon string `json:"icon,omitempty" yaml:"icon,omitempty"` - - // Search keywords for the package. - Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"` - - // Homepage of the application package. - Home string `json:"home,omitempty" yaml:"home,omitempty"` - - // Source specifies the upstream URL, e.g. https://github.com/foo/bar.git, - // file://host/path, etc. - // hosting the resource files specified in Base and Overlays. - // This is useful in the fork/rebase workflow. - Source string `json:"source,omitempty" yaml:"source,omitempty"` - - // Version of the package. - PackageVersion string `json:"packageVersion,omitempty" yaml:"packageVersion,omitempty"` -} +package types // Manifest has all the information to expand of generate the k8s api resources. // It can be used by kubectl or some other tooling. // A manifest could be either a Base or an Overlay. +// TODO: rename Manifest to Kustomization type Manifest struct { - metav1.TypeMeta `json:",inline" yaml:",inline"` - // Standard object's metadata. - // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata - metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"` - - // TODO: figure out if we need field ManifestVersion. - // See: https://github.com/kubernetes/kubernetes/pull/52570/files/3eea91793dfbc3fdb0799589fac3790c4cde58a4#r140391019 - // Version of the manifest. - // ManifestVersion string `json:"manifestVersion,omitempty" yaml:"manifestVersion,omitempty"` + // KustomizationName is a documentation field - a name for the customizations + // in a marshalled version of this struct, that survives YAML unmarshalling + // that discards comments. + KustomizationName string `json:"kustomizationName,omitempty" yaml:"kustomizationName,omitempty"` // NamePrefix will prefix the names of all resources mentioned in the manifest // including generated configmaps and secrets.