Skip to content

Commit 0a40cfd

Browse files
authored
Merge pull request kubesphere#3465 from xyz-li/app-fix
Fix nil pointer and delete helmRelease
2 parents b2fc118 + dd8429c commit 0a40cfd

File tree

17 files changed

+406
-319
lines changed

17 files changed

+406
-319
lines changed

cmd/controller-manager/app/server.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ func run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
228228
klog.Fatal("Unable to create helm category controller")
229229
}
230230

231+
var opS3Client s3.Interface
231232
if !s.OpenPitrixOptions.AppStoreConfIsEmpty() {
232-
storageClient, err := s3.NewS3Client(s.OpenPitrixOptions.S3Options)
233+
opS3Client, err = s3.NewS3Client(s.OpenPitrixOptions.S3Options)
233234
if err != nil {
234235
klog.Fatalf("failed to connect to s3, please check openpitrix s3 service status, error: %v", err)
235236
}
@@ -242,15 +243,17 @@ func run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
242243
if err != nil {
243244
klog.Fatalf("Unable to create helm application version controller, error: %s ", err)
244245
}
246+
}
245247

246-
err = (&helmrelease.ReconcileHelmRelease{
247-
StorageClient: storageClient,
248-
KsFactory: informerFactory.KubeSphereSharedInformerFactory(),
249-
}).SetupWithManager(mgr)
248+
err = (&helmrelease.ReconcileHelmRelease{
249+
// nil interface is valid value.
250+
StorageClient: opS3Client,
251+
KsFactory: informerFactory.KubeSphereSharedInformerFactory(),
252+
MultiClusterEnable: s.MultiClusterOptions.Enable,
253+
}).SetupWithManager(mgr)
250254

251-
if err != nil {
252-
klog.Fatalf("Unable to create helm release controller, error: %s", err)
253-
}
255+
if err != nil {
256+
klog.Fatalf("Unable to create helm release controller, error: %s", err)
254257
}
255258

256259
selector, _ := labels.Parse(s.ApplicationSelector)

config/crds/application.kubesphere.io_helmrepos.yaml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/application/v1alpha1/helmrepo_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type HelmRepoStatus struct {
9292
// +kubebuilder:resource:scope=Cluster,path=helmrepos,shortName=hrepo
9393
// +kubebuilder:subresource:status
9494
// +kubebuilder:printcolumn:name="name",type=string,JSONPath=`.spec.name`
95-
// +kubebuilder:printcolumn:name="Workspace",type=string,JSONPath=`.metadata.labels.kubesphere\\.io/workspace`
95+
// +kubebuilder:printcolumn:name="Workspace",type="string",JSONPath=".metadata.labels.kubesphere\\.io/workspace"
9696
// +kubebuilder:printcolumn:name="url",type=string,JSONPath=`.spec.url`
9797
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state"
9898
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

pkg/apiserver/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (conf *Config) ToMap() map[string]bool {
205205
if conf.OpenPitrixOptions == nil {
206206
result["openpitrix.appstore"] = false
207207
} else {
208-
result["openpitrix.appstore"] = conf.OpenPitrixOptions.AppStoreConfIsEmpty()
208+
result["openpitrix.appstore"] = !conf.OpenPitrixOptions.AppStoreConfIsEmpty()
209209
}
210210
continue
211211
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2019 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 helmrelease
18+
19+
import (
20+
"context"
21+
"k8s.io/apimachinery/pkg/types"
22+
"k8s.io/klog"
23+
"kubesphere.io/kubesphere/pkg/apis/application/v1alpha1"
24+
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix/helmrepoindex"
25+
"path"
26+
"strings"
27+
)
28+
29+
func (r *ReconcileHelmRelease) GetChartData(rls *v1alpha1.HelmRelease) (chartName string, chartData []byte, err error) {
30+
if rls.Spec.RepoId != "" && rls.Spec.RepoId != v1alpha1.AppStoreRepoId {
31+
// load chart data from helm repo
32+
repo := v1alpha1.HelmRepo{}
33+
err := r.Get(context.TODO(), types.NamespacedName{Name: rls.Spec.RepoId}, &repo)
34+
if err != nil {
35+
klog.Errorf("get helm repo %s failed, error: %v", rls.Spec.RepoId, err)
36+
return chartName, chartData, ErrGetRepoFailed
37+
}
38+
39+
index, err := helmrepoindex.ByteArrayToSavedIndex([]byte(repo.Status.Data))
40+
41+
if version := index.GetApplicationVersion(rls.Spec.ApplicationId, rls.Spec.ApplicationVersionId); version != nil {
42+
url := version.Spec.URLs[0]
43+
if !(strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "s3://")) {
44+
url = repo.Spec.Url + "/" + url
45+
}
46+
buf, err := helmrepoindex.LoadChart(context.TODO(), url, &repo.Spec.Credential)
47+
if err != nil {
48+
klog.Infof("load chart failed, error: %s", err)
49+
return chartName, chartData, ErrLoadChartFailed
50+
}
51+
chartData = buf.Bytes()
52+
chartName = version.Name
53+
} else {
54+
klog.Errorf("get app version: %s failed", rls.Spec.ApplicationVersionId)
55+
return chartName, chartData, ErrGetAppVersionFailed
56+
}
57+
} else {
58+
// load chart data from helm application version
59+
appVersion := &v1alpha1.HelmApplicationVersion{}
60+
err = r.Get(context.TODO(), types.NamespacedName{Name: rls.Spec.ApplicationVersionId}, appVersion)
61+
if err != nil {
62+
klog.Errorf("get app version %s failed, error: %v", rls.Spec.ApplicationVersionId, err)
63+
return chartName, chartData, ErrGetAppVersionFailed
64+
}
65+
66+
if r.StorageClient == nil {
67+
return "", nil, ErrS3Config
68+
}
69+
chartData, err = r.StorageClient.Read(path.Join(appVersion.GetWorkspace(), appVersion.Name))
70+
if err != nil {
71+
klog.Errorf("load chart from storage failed, error: %s", err)
72+
return chartName, chartData, ErrLoadChartFromStorageFailed
73+
}
74+
75+
chartName = appVersion.GetTrueName()
76+
}
77+
return
78+
}

0 commit comments

Comments
 (0)