github.com/kruglovmax/helm@v3.0.0-beta.3+incompatible/pkg/chart/metadata.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package chart
    17  
    18  // Maintainer describes a Chart maintainer.
    19  type Maintainer struct {
    20  	// Name is a user name or organization name
    21  	Name string `json:"name,omitempty"`
    22  	// Email is an optional email address to contact the named maintainer
    23  	Email string `json:"email,omitempty"`
    24  	// URL is an optional URL to an address for the named maintainer
    25  	URL string `json:"url,omitempty"`
    26  }
    27  
    28  // Metadata for a Chart file. This models the structure of a Chart.yaml file.
    29  type Metadata struct {
    30  	// The name of the chart
    31  	Name string `json:"name,omitempty"`
    32  	// The URL to a relevant project page, git repo, or contact person
    33  	Home string `json:"home,omitempty"`
    34  	// Source is the URL to the source code of this chart
    35  	Sources []string `json:"sources,omitempty"`
    36  	// A SemVer 2 conformant version string of the chart
    37  	Version string `json:"version,omitempty"`
    38  	// A one-sentence description of the chart
    39  	Description string `json:"description,omitempty"`
    40  	// A list of string keywords
    41  	Keywords []string `json:"keywords,omitempty"`
    42  	// A list of name and URL/email address combinations for the maintainer(s)
    43  	Maintainers []*Maintainer `json:"maintainers,omitempty"`
    44  	// The URL to an icon file.
    45  	Icon string `json:"icon,omitempty"`
    46  	// The API Version of this chart.
    47  	APIVersion string `json:"apiVersion,omitempty"`
    48  	// The condition to check to enable chart
    49  	Condition string `json:"condition,omitempty"`
    50  	// The tags to check to enable chart
    51  	Tags string `json:"tags,omitempty"`
    52  	// The version of the application enclosed inside of this chart.
    53  	AppVersion string `json:"appVersion,omitempty"`
    54  	// Whether or not this chart is deprecated
    55  	Deprecated bool `json:"deprecated,omitempty"`
    56  	// Annotations are additional mappings uninterpreted by Helm,
    57  	// made available for inspection by other applications.
    58  	Annotations map[string]string `json:"annotations,omitempty"`
    59  	// KubeVersion is a SemVer constraint specifying the version of Kubernetes required.
    60  	KubeVersion string `json:"kubeVersion,omitempty"`
    61  	// Dependencies are a list of dependencies for a chart.
    62  	Dependencies []*Dependency `json:"dependencies,omitempty"`
    63  	// Specifies the chart type: application or library
    64  	Type string `json:"type,omitempty"`
    65  }
    66  
    67  // Validate checks the metadata for known issues, returning an error if metadata is not correct
    68  func (md *Metadata) Validate() error {
    69  	if md == nil {
    70  		return ValidationError("chart.metadata is required")
    71  	}
    72  	if md.APIVersion == "" {
    73  		return ValidationError("chart.metadata.apiVersion is required")
    74  	}
    75  	if md.Name == "" {
    76  		return ValidationError("chart.metadata.name is required")
    77  	}
    78  	if md.Version == "" {
    79  		return ValidationError("chart.metadata.version is required")
    80  	}
    81  	if !isValidChartType(md.Type) {
    82  		return ValidationError("chart.metadata.type must be application or library")
    83  	}
    84  	// TODO validate valid semver here?
    85  	return nil
    86  }
    87  
    88  func isValidChartType(in string) bool {
    89  	switch in {
    90  	case "", "application", "library":
    91  		return true
    92  	}
    93  	return false
    94  }