github.com/sri09kanth/helm@v3.0.0-beta.3+incompatible/pkg/chartutil/capabilities.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 chartutil
    17  
    18  import (
    19  	"k8s.io/client-go/kubernetes/scheme"
    20  )
    21  
    22  var (
    23  	// DefaultVersionSet is the default version set, which includes only Core V1 ("v1").
    24  	DefaultVersionSet = allKnownVersions()
    25  
    26  	// DefaultCapabilities is the default set of capabilities.
    27  	DefaultCapabilities = &Capabilities{
    28  		KubeVersion: KubeVersion{
    29  			Version: "v1.14.0",
    30  			Major:   "1",
    31  			Minor:   "14",
    32  		},
    33  		APIVersions: DefaultVersionSet,
    34  	}
    35  )
    36  
    37  // Capabilities describes the capabilities of the Kubernetes cluster.
    38  type Capabilities struct {
    39  	// KubeVersion is the Kubernetes version.
    40  	KubeVersion KubeVersion
    41  	// APIversions are supported Kubernetes API versions.
    42  	APIVersions VersionSet
    43  }
    44  
    45  // KubeVersion is the Kubernetes version.
    46  type KubeVersion struct {
    47  	Version string // Kubernetes version
    48  	Major   string // Kubernetes major version
    49  	Minor   string // Kubernetes minor version
    50  }
    51  
    52  // String implements fmt.Stringer
    53  func (kv *KubeVersion) String() string { return kv.Version }
    54  
    55  // GitVersion returns the Kubernetes version string.
    56  //
    57  // Deprecated: use KubeVersion.Version.
    58  func (kv *KubeVersion) GitVersion() string { return kv.Version }
    59  
    60  // VersionSet is a set of Kubernetes API versions.
    61  type VersionSet []string
    62  
    63  // Has returns true if the version string is in the set.
    64  //
    65  //	vs.Has("apps/v1")
    66  func (v VersionSet) Has(apiVersion string) bool {
    67  	for _, x := range v {
    68  		if x == apiVersion {
    69  			return true
    70  		}
    71  	}
    72  	return false
    73  }
    74  
    75  func allKnownVersions() VersionSet {
    76  	groups := scheme.Scheme.PrioritizedVersionsAllGroups()
    77  	vs := make(VersionSet, 0, len(groups))
    78  	for _, gv := range groups {
    79  		vs = append(vs, gv.String())
    80  	}
    81  	return vs
    82  }