kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/application/v1alpha1/helmrelease_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 22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 24 "kubesphere.io/api/constants" 25 ) 26 27 const ( 28 ResourceKindHelmRelease = "HelmRelease" 29 ResourceSingularHelmRelease = "helmrelease" 30 ResourcePluralHelmRelease = "helmreleases" 31 ) 32 33 // HelmReleaseSpec defines the desired state of HelmRelease 34 type HelmReleaseSpec struct { 35 // Name of the release 36 Name string `json:"name"` 37 // Message got from frontend 38 Description string `json:"description,omitempty"` 39 // helm release values.yaml 40 Values []byte `json:"values,omitempty"` 41 // The name of the chart which will be installed. 42 ChartName string `json:"chartName"` 43 // Specify the exact chart version to install. If this is not specified, the latest version is installed 44 ChartVersion string `json:"chartVersion"` 45 // appVersion from Chart.yaml 46 ChartAppVersion string `json:"chartAppVer,omitempty"` 47 // id of the repo 48 RepoId string `json:"repoId,omitempty"` 49 // id of the helmapplication 50 ApplicationId string `json:"appId,omitempty"` 51 // application version id 52 ApplicationVersionId string `json:"appVerId,omitempty"` 53 // expected release version, when this version is not equal status.version, the release need upgrade 54 // this filed should be modified when any filed of the spec modified. 55 Version int `json:"version"` 56 } 57 58 type HelmReleaseDeployStatus struct { 59 // A human readable message indicating details about why the release is in this state. 60 Message string `json:"message,omitempty"` 61 // current state of the release 62 State string `json:"state"` 63 // deploy time, upgrade time or check status time 64 Time metav1.Time `json:"deployTime"` 65 } 66 67 // HelmReleaseStatus defines the observed state of HelmRelease 68 type HelmReleaseStatus struct { 69 // current state 70 State string `json:"state"` 71 // A human readable message indicating details about why the release is in this state. 72 Message string `json:"message,omitempty"` 73 // current release version 74 Version int `json:"version,omitempty"` 75 // deploy status list of history, which will store at most 10 state 76 DeployStatus []HelmReleaseDeployStatus `json:"deployStatus,omitempty"` 77 // last update time 78 LastUpdate metav1.Time `json:"lastUpdate,omitempty"` 79 // last deploy time or upgrade time 80 LastDeployed *metav1.Time `json:"lastDeployed,omitempty"` 81 } 82 83 // +kubebuilder:object:root=true 84 // +kubebuilder:resource:scope=Cluster,shortName=hrls 85 // +kubebuilder:subresource:status 86 // +kubebuilder:printcolumn:name="Release Name",type=string,JSONPath=".spec.name" 87 // +kubebuilder:printcolumn:name="Workspace",type="string",JSONPath=".metadata.labels.kubesphere\\.io/workspace" 88 // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.kubesphere\\.io/cluster" 89 // +kubebuilder:printcolumn:name="Namespace",type="string",JSONPath=".metadata.labels.kubesphere\\.io/namespace" 90 // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state" 91 // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" 92 // +genclient 93 // +genclient:nonNamespaced 94 // +kubebuilder:object:root=true 95 96 // HelmRelease is the Schema for the helmreleases API 97 type HelmRelease struct { 98 metav1.TypeMeta `json:",inline"` 99 metav1.ObjectMeta `json:"metadata,omitempty"` 100 101 Spec HelmReleaseSpec `json:"spec,omitempty"` 102 Status HelmReleaseStatus `json:"status,omitempty"` 103 } 104 105 // +kubebuilder:object:root=true 106 // +kubebuilder:object:root=true 107 108 // HelmReleaseList contains a list of HelmRelease 109 type HelmReleaseList struct { 110 metav1.TypeMeta `json:",inline"` 111 metav1.ListMeta `json:"metadata,omitempty"` 112 Items []HelmRelease `json:"items"` 113 } 114 115 func init() { 116 SchemeBuilder.Register(&HelmRelease{}, &HelmReleaseList{}) 117 } 118 119 func (in *HelmRelease) GetCreator() string { 120 return getValue(in.Annotations, constants.CreatorAnnotationKey) 121 } 122 123 func (in *HelmRelease) GetTrueName() string { 124 return in.Spec.Name 125 } 126 127 func (in *HelmRelease) GetChartVersionName() string { 128 appV := in.GetChartAppVersion() 129 if appV != "" { 130 return fmt.Sprintf("%s [%s]", in.GetChartVersion(), appV) 131 } else { 132 return in.GetChartVersion() 133 } 134 } 135 136 func (in *HelmRelease) GetChartAppVersion() string { 137 return in.Spec.ChartAppVersion 138 } 139 140 func (in *HelmRelease) GetChartVersion() string { 141 return in.Spec.ChartVersion 142 } 143 144 func (in *HelmRelease) GetRlsCluster() string { 145 return getValue(in.Labels, constants.ClusterNameLabelKey) 146 } 147 148 func (in *HelmRelease) GetWorkspace() string { 149 return getValue(in.Labels, constants.WorkspaceLabelKey) 150 } 151 152 func (in *HelmRelease) GetRlsNamespace() string { 153 return getValue(in.Labels, constants.NamespaceLabelKey) 154 }