kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/application/v1alpha1/helmapplicationversion_types.go (about)

     1  /*
     2  Copyright 2020 The KubeSphere Authors.
     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 v1alpha1
    18  
    19  import (
    20  	"fmt"
    21  	"strings"
    22  
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  
    25  	"kubesphere.io/api/constants"
    26  )
    27  
    28  const (
    29  	ResourceKindHelmApplicationVersion     = "HelmApplicationVersion"
    30  	ResourceSingularHelmApplicationVersion = "helmapplicationversion"
    31  	ResourcePluralHelmApplicationVersion   = "helmapplicationversions"
    32  )
    33  
    34  // HelmApplicationVersionSpec defines the desired state of HelmApplicationVersion
    35  type HelmApplicationVersionSpec struct {
    36  	// metadata from chart
    37  	*Metadata `json:",inline"`
    38  	// chart url
    39  	URLs []string `json:"urls,omitempty"`
    40  	// raw data of chart, it will !!!NOT!!! be save to etcd
    41  	Data []byte `json:"data,omitempty"`
    42  
    43  	// dataKey in the storage
    44  	DataKey string `json:"dataKey,omitempty"`
    45  
    46  	// chart create time
    47  	Created *metav1.Time `json:"created,omitempty"`
    48  
    49  	// chart digest
    50  	Digest string `json:"digest,omitempty"`
    51  }
    52  
    53  // HelmApplicationVersionStatus defines the observed state of HelmApplicationVersion
    54  type HelmApplicationVersionStatus struct {
    55  	State string  `json:"state,omitempty"`
    56  	Audit []Audit `json:"audit,omitempty"`
    57  }
    58  
    59  // +kubebuilder:object:root=true
    60  // +kubebuilder:resource:scope=Cluster,shortName=happver
    61  // +kubebuilder:subresource:status
    62  // +kubebuilder:printcolumn:name="application name",type=string,JSONPath=`.spec.name`
    63  // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state"
    64  // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
    65  // +genclient
    66  // +genclient:nonNamespaced
    67  // +kubebuilder:object:root=true
    68  
    69  // HelmApplicationVersion is the Schema for the helmapplicationversions API
    70  type HelmApplicationVersion struct {
    71  	metav1.TypeMeta   `json:",inline"`
    72  	metav1.ObjectMeta `json:"metadata,omitempty"`
    73  
    74  	Spec   HelmApplicationVersionSpec   `json:"spec,omitempty"`
    75  	Status HelmApplicationVersionStatus `json:"status,omitempty"`
    76  }
    77  
    78  // Maintainer describes a Chart maintainer.
    79  type Maintainer struct {
    80  	// Name is a user name or organization name
    81  	Name string `json:"name,omitempty"`
    82  	// Email is an optional email address to contact the named maintainer
    83  	Email string `json:"email,omitempty"`
    84  	// URL is an optional URL to an address for the named maintainer
    85  	URL string `json:"url,omitempty"`
    86  }
    87  
    88  // Metadata for a Chart file. This models the structure of a Chart.yaml file.
    89  type Metadata struct {
    90  	// The name of the chart
    91  	Name string `json:"name,omitempty"`
    92  	// The URL to a relevant project page, git repo, or contact person
    93  	Home string `json:"home,omitempty"`
    94  	// Source is the URL to the source code of this chart
    95  	Sources []string `json:"sources,omitempty"`
    96  	// A SemVer 2 conformant version string of the chart
    97  	Version string `json:"version,omitempty"`
    98  	// A one-sentence description of the chart
    99  	Description string `json:"description,omitempty"`
   100  	// A list of string keywords
   101  	Keywords []string `json:"keywords,omitempty"`
   102  	// A list of name and URL/email address combinations for the maintainer(s)
   103  	Maintainers []*Maintainer `json:"maintainers,omitempty"`
   104  	// The URL to an icon file.
   105  	Icon string `json:"icon,omitempty"`
   106  	// The API Version of this chart.
   107  	APIVersion string `json:"apiVersion,omitempty"`
   108  	// The condition to check to enable chart
   109  	Condition string `json:"condition,omitempty"`
   110  	// The tags to check to enable chart
   111  	Tags string `json:"tags,omitempty"`
   112  	// The version of the application enclosed inside of this chart.
   113  	AppVersion string `json:"appVersion,omitempty"`
   114  	// Whether or not this chart is deprecated
   115  	Deprecated bool `json:"deprecated,omitempty"`
   116  	// Annotations are additional mappings uninterpreted by Helm,
   117  	// made available for inspection by other applications.
   118  	Annotations map[string]string `json:"annotations,omitempty"`
   119  	// KubeVersion is a SemVer constraint specifying the version of Kubernetes required.
   120  	KubeVersion string `json:"kubeVersion,omitempty"`
   121  	// Dependencies are a list of dependencies for a chart.
   122  	Dependencies []*Dependency `json:"dependencies,omitempty"`
   123  	// Specifies the chart type: application or library
   124  	Type string `json:"type,omitempty"`
   125  }
   126  
   127  type Audit struct {
   128  	// audit message
   129  	Message string `json:"message,omitempty"`
   130  	// audit state: submitted, passed, draft, active, rejected, suspended
   131  	State string `json:"state,omitempty"`
   132  	// audit time
   133  	Time metav1.Time `json:"time"`
   134  	// audit operator
   135  	Operator     string `json:"operator,omitempty"`
   136  	OperatorType string `json:"operatorType,omitempty"`
   137  }
   138  
   139  // Dependency describes a chart upon which another chart depends.
   140  // Dependencies can be used to express developer intent, or to capture the state
   141  // of a chart.
   142  type Dependency struct {
   143  	// Name is the name of the dependency.
   144  	// This must mach the name in the dependency's Chart.yaml.
   145  	Name string `json:"name"`
   146  	// Version is the version (range) of this chart.
   147  	// A lock file will always produce a single version, while a dependency
   148  	// may contain a semantic version range.
   149  	Version string `json:"version,omitempty"`
   150  	// The URL to the repository.
   151  	// Appending `index.yaml` to this string should result in a URL that can be
   152  	// used to fetch the repository index.
   153  	Repository string `json:"repository"`
   154  	// A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled )
   155  	Condition string `json:"condition,omitempty"`
   156  	// Tags can be used to group charts for enabling/disabling together
   157  	Tags []string `json:"tags,omitempty"`
   158  	// Enabled bool determines if chart should be loaded
   159  	Enabled bool `json:"enabled,omitempty"`
   160  	// ImportValues holds the mapping of source values to parent key to be imported. Each item can be a
   161  	// string or pair of child/parent sublist items.
   162  	// ImportValues []interface{} `json:"import_values,omitempty"`
   163  
   164  	// Alias usable alias to be used for the chart
   165  	Alias string `json:"alias,omitempty"`
   166  }
   167  
   168  // +kubebuilder:object:root=true
   169  // +kubebuilder:object:root=true
   170  
   171  // HelmApplicationVersionList contains a list of HelmApplicationVersion
   172  type HelmApplicationVersionList struct {
   173  	metav1.TypeMeta `json:",inline"`
   174  	metav1.ListMeta `json:"metadata,omitempty"`
   175  	Items           []HelmApplicationVersion `json:"items"`
   176  }
   177  
   178  func init() {
   179  	SchemeBuilder.Register(&HelmApplicationVersion{}, &HelmApplicationVersionList{})
   180  }
   181  
   182  func (in *HelmApplicationVersion) GetCreator() string {
   183  	return getValue(in.Annotations, constants.CreatorAnnotationKey)
   184  }
   185  
   186  func (in *HelmApplicationVersion) GetHelmApplicationVersionId() string {
   187  	return in.Name
   188  }
   189  
   190  func (in *HelmApplicationVersion) GetWorkspace() string {
   191  	return getValue(in.Labels, constants.WorkspaceLabelKey)
   192  }
   193  
   194  func (in *HelmApplicationVersion) GetVersionName() string {
   195  	appV := in.GetChartAppVersion()
   196  	if appV != "" {
   197  		return fmt.Sprintf("%s [%s]", in.GetChartVersion(), appV)
   198  	} else {
   199  		return in.GetChartVersion()
   200  	}
   201  }
   202  
   203  func (in *HelmApplicationVersion) GetHelmApplicationId() string {
   204  	return getValue(in.Labels, constants.ChartApplicationIdLabelKey)
   205  }
   206  
   207  func (in *HelmApplicationVersion) GetSemver() string {
   208  	return strings.Split(in.GetVersionName(), " ")[0]
   209  }
   210  
   211  func (in *HelmApplicationVersion) GetTrueName() string {
   212  	return in.Spec.Name
   213  }
   214  
   215  func (in *HelmApplicationVersion) GetChartVersion() string {
   216  	return in.Spec.Version
   217  }
   218  
   219  func (in *HelmApplicationVersion) GetChartAppVersion() string {
   220  	return in.Spec.AppVersion
   221  }
   222  
   223  func (in *HelmApplicationVersion) GetHelmRepoId() string {
   224  	return getValue(in.Labels, constants.ChartRepoIdLabelKey)
   225  }
   226  
   227  func (in *HelmApplicationVersion) State() string {
   228  	if in.Status.State == "" {
   229  		return StateDraft
   230  	}
   231  
   232  	return in.Status.State
   233  }