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 import "time" 19 20 // Dependency describes a chart upon which another chart depends. 21 // 22 // Dependencies can be used to express developer intent, or to capture the state 23 // of a chart. 24 type Dependency struct { 25 // Name is the name of the dependency. 26 // 27 // This must mach the name in the dependency's Chart.yaml. 28 Name string `json:"name"` 29 // Version is the version (range) of this chart. 30 // 31 // A lock file will always produce a single version, while a dependency 32 // may contain a semantic version range. 33 Version string `json:"version,omitempty"` 34 // The URL to the repository. 35 // 36 // Appending `index.yaml` to this string should result in a URL that can be 37 // used to fetch the repository index. 38 Repository string `json:"repository"` 39 // A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled ) 40 Condition string `json:"condition,omitempty"` 41 // Tags can be used to group charts for enabling/disabling together 42 Tags []string `json:"tags,omitempty"` 43 // Enabled bool determines if chart should be loaded 44 Enabled bool `json:"enabled,omitempty"` 45 // ImportValues holds the mapping of source values to parent key to be imported. Each item can be a 46 // string or pair of child/parent sublist items. 47 ImportValues []interface{} `json:"import-values,omitempty"` 48 // Alias usable alias to be used for the chart 49 Alias string `json:"alias,omitempty"` 50 } 51 52 // Validate checks for common problems with the dependency datastructure in 53 // the chart. This check must be done at load time before the dependency's charts are 54 // loaded. 55 func (d *Dependency) Validate() error { 56 if d == nil { 57 return ValidationError("dependencies must not contain empty or null nodes") 58 } 59 d.Name = sanitizeString(d.Name) 60 d.Version = sanitizeString(d.Version) 61 d.Repository = sanitizeString(d.Repository) 62 d.Condition = sanitizeString(d.Condition) 63 for i := range d.Tags { 64 d.Tags[i] = sanitizeString(d.Tags[i]) 65 } 66 if d.Alias != "" && !aliasNameFormat.MatchString(d.Alias) { 67 return ValidationErrorf("dependency %q has disallowed characters in the alias", d.Name) 68 } 69 return nil 70 } 71 72 // Lock is a lock file for dependencies. 73 // 74 // It represents the state that the dependencies should be in. 75 type Lock struct { 76 // Generated is the date the lock file was last generated. 77 Generated time.Time `json:"generated"` 78 // Digest is a hash of the dependencies in Chart.yaml. 79 Digest string `json:"digest"` 80 // Dependencies is the list of dependencies that this lock file has locked. 81 Dependencies []*Dependency `json:"dependencies"` 82 } 83