github.com/cloudposse/helm@v2.2.3+incompatible/pkg/releaseutil/manifest.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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 releaseutil
    18  
    19  import (
    20  	"fmt"
    21  	"strings"
    22  )
    23  
    24  // SimpleHead defines what the structure of the head of a manifest file
    25  type SimpleHead struct {
    26  	Version  string `json:"apiVersion"`
    27  	Kind     string `json:"kind,omitempty"`
    28  	Metadata *struct {
    29  		Name        string            `json:"name"`
    30  		Annotations map[string]string `json:"annotations"`
    31  	} `json:"metadata,omitempty"`
    32  }
    33  
    34  // SplitManifests takes a string of manifest and returns a map contains individual manifests
    35  func SplitManifests(bigfile string) map[string]string {
    36  	// This is not the best way of doing things, but it's how k8s itself does it.
    37  	// Basically, we're quickly splitting a stream of YAML documents into an
    38  	// array of YAML docs. In the current implementation, the file name is just
    39  	// a place holder, and doesn't have any further meaning.
    40  	sep := "\n---\n"
    41  	tpl := "manifest-%d"
    42  	res := map[string]string{}
    43  	tmp := strings.Split(bigfile, sep)
    44  	for i, d := range tmp {
    45  		res[fmt.Sprintf(tpl, i)] = d
    46  	}
    47  	return res
    48  }