kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/application/v1alpha1/helmrepo_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 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 22 "kubesphere.io/api/constants" 23 ) 24 25 const ( 26 ResourceKindHelmRepo = "HelmRepo" 27 ResourceSingularHelmRepo = "helmrepo" 28 ResourcePluralHelmRepo = "helmrepos" 29 ) 30 31 type HelmRepoCredential struct { 32 // chart repository username 33 Username string `json:"username,omitempty"` 34 // chart repository password 35 Password string `json:"password,omitempty"` 36 // identify HTTPS client using this SSL certificate file 37 CertFile string `json:"certFile,omitempty"` 38 // identify HTTPS client using this SSL key file 39 KeyFile string `json:"keyFile,omitempty"` 40 // verify certificates of HTTPS-enabled servers using this CA bundle 41 CAFile string `json:"caFile,omitempty"` 42 // skip tls certificate checks for the repository, default is ture 43 InsecureSkipTLSVerify *bool `json:"insecureSkipTLSVerify,omitempty"` 44 45 S3Config `json:",inline"` 46 } 47 48 type S3Config struct { 49 AccessKeyID string `json:"accessKeyID,omitempty"` 50 SecretAccessKey string `json:"secretAccessKey,omitempty"` 51 } 52 53 // HelmRepoSpec defines the desired state of HelmRepo 54 type HelmRepoSpec struct { 55 // name of the repo 56 Name string `json:"name"` 57 // helm repo url 58 Url string `json:"url"` 59 // helm repo credential 60 Credential HelmRepoCredential `json:"credential,omitempty"` 61 // chart repo description from frontend 62 Description string `json:"description,omitempty"` 63 // sync period in seconds, no sync when SyncPeriod=0, the minimum SyncPeriod is 180s 64 SyncPeriod int `json:"syncPeriod,omitempty"` 65 // expected repo version, when this version is not equal status.version, the repo need upgrade 66 // this filed should be modified when any filed of the spec modified. 67 Version int `json:"version,omitempty"` 68 } 69 70 type HelmRepoSyncState struct { 71 // last sync state, valid state are: "failed", "success", and "" 72 State string `json:"state,omitempty"` 73 // A human readable message indicating details about why the repo is in this state. 74 Message string `json:"message,omitempty"` 75 SyncTime *metav1.Time `json:"syncTime"` 76 } 77 78 // HelmRepoStatus defines the observed state of HelmRepo 79 type HelmRepoStatus struct { 80 // repo index 81 Data string `json:"data,omitempty"` 82 // status last update time 83 LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"` 84 // current state of the repo, successful, failed or syncing 85 State string `json:"state,omitempty"` 86 // sync state list of history, which will store at most 10 state 87 SyncState []HelmRepoSyncState `json:"syncState,omitempty"` 88 // if status.version!=spec.Version, we need sync the repo now 89 Version int `json:"version,omitempty"` 90 } 91 92 // +kubebuilder:object:root=true 93 // +kubebuilder:resource:scope=Cluster,path=helmrepos,shortName=hrepo 94 // +kubebuilder:subresource:status 95 // +kubebuilder:printcolumn:name="name",type=string,JSONPath=`.spec.name` 96 // +kubebuilder:printcolumn:name="Workspace",type="string",JSONPath=".metadata.labels.kubesphere\\.io/workspace" 97 // +kubebuilder:printcolumn:name="url",type=string,JSONPath=`.spec.url` 98 // +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state" 99 // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" 100 // +genclient 101 // +genclient:nonNamespaced 102 // +kubebuilder:object:root=true 103 104 // HelmRepo is the Schema for the helmrepoes API 105 type HelmRepo struct { 106 metav1.TypeMeta `json:",inline"` 107 metav1.ObjectMeta `json:"metadata,omitempty"` 108 109 Spec HelmRepoSpec `json:"spec,omitempty"` 110 Status HelmRepoStatus `json:"status,omitempty"` 111 } 112 113 // +kubebuilder:object:root=true 114 // +kubebuilder:object:root=true 115 116 // HelmRepoList contains a list of HelmRepo 117 type HelmRepoList struct { 118 metav1.TypeMeta `json:",inline"` 119 metav1.ListMeta `json:"metadata,omitempty"` 120 Items []HelmRepo `json:"items"` 121 } 122 123 func init() { 124 SchemeBuilder.Register(&HelmRepo{}, &HelmRepoList{}) 125 } 126 127 func (in *HelmRepo) GetTrueName() string { 128 return in.Spec.Name 129 } 130 131 func (in *HelmRepo) GetHelmRepoId() string { 132 return in.Name 133 } 134 135 func (in *HelmRepo) GetWorkspace() string { 136 return getValue(in.Labels, constants.WorkspaceLabelKey) 137 } 138 139 func (in *HelmRepo) GetCreator() string { 140 return getValue(in.Annotations, constants.CreatorAnnotationKey) 141 }