diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-04-16 18:09:13 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2019-04-16 18:09:27 -0700 |
commit | bf49d552b003072c6bc64ae838a4699c1f4028bd (patch) | |
tree | 57c2b6130781f8215b0544e6b6f126ec8e2f8152 /src/k8splugin/internal/helm/helm.go | |
parent | 244578803033f17781b10be283aef43fa6f0aa60 (diff) |
Replace Kind with GroupVersionKind
Kind is not unique to track resources in Kubernetes
GroupVersionKind is unique. We are just using that to
track our data. It is abstracted behind a couple of new
types for templates and resources.
This change makes a lot of the old kind based operations
redundant and simplified.
Issue-ID: MULTICLOUD-573
Change-Id: I8f4ded2ba6a0821a8fbd679dc99ce3a44d805524
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/helm/helm.go')
-rw-r--r-- | src/k8splugin/internal/helm/helm.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/k8splugin/internal/helm/helm.go b/src/k8splugin/internal/helm/helm.go index 65a36d6b..1ab701ae 100644 --- a/src/k8splugin/internal/helm/helm.go +++ b/src/k8splugin/internal/helm/helm.go @@ -28,8 +28,10 @@ import ( "github.com/ghodss/yaml" pkgerrors "github.com/pkg/errors" - + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/runtime/serializer/json" "k8s.io/apimachinery/pkg/util/validation" + k8syaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/helm/pkg/chartutil" "k8s.io/helm/pkg/manifest" "k8s.io/helm/pkg/proto/hapi/chart" @@ -143,10 +145,11 @@ func (h *TemplateClient) ensureDirectory(f string) error { } // GenerateKubernetesArtifacts a mapping of type to fully evaluated helm template -func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string, values []string) (map[string][]string, error) { +func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string, + values []string) ([]KubernetesResourceTemplate, error) { var outputDir, chartPath, namespace, releaseName string - var retData map[string][]string + var retData []KubernetesResourceTemplate releaseName = h.releaseName namespace = h.kubeNameSpace @@ -226,7 +229,6 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile var manifestsToRender []manifest.Manifest //render all manifests in the chart manifestsToRender = listManifests - retData = make(map[string][]string) for _, m := range tiller.SortByKind(manifestsToRender) { data := m.Content b := filepath.Base(m.Name) @@ -249,11 +251,31 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile return retData, err } - if val, ok := retData[m.Head.Kind]; ok { - retData[m.Head.Kind] = append(val, mfilePath) - } else { - retData[m.Head.Kind] = []string{mfilePath} + gvk, err := getGroupVersionKind(data) + if err != nil { + return retData, err } + + kres := KubernetesResourceTemplate{ + GVK: gvk, + FilePath: mfilePath, + } + retData = append(retData, kres) } return retData, nil } + +func getGroupVersionKind(data string) (schema.GroupVersionKind, error) { + out, err := k8syaml.ToJSON([]byte(data)) + if err != nil { + return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Converting yaml to json") + } + + simpleMeta := json.SimpleMetaFactory{} + gvk, err := simpleMeta.Interpret(out) + if err != nil { + return schema.GroupVersionKind{}, pkgerrors.Wrap(err, "Parsing apiversion and kind") + } + + return *gvk, nil +} |