Skip to content

Commit

Permalink
Merge pull request kubesphere#3465 from xyz-li/app-fix
Browse files Browse the repository at this point in the history
Fix nil pointer and delete helmRelease
  • Loading branch information
ks-ci-bot authored Mar 19, 2021
2 parents b2fc118 + dd8429c commit 0a40cfd
Show file tree
Hide file tree
Showing 17 changed files with 406 additions and 319 deletions.
19 changes: 11 additions & 8 deletions cmd/controller-manager/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ func run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
klog.Fatal("Unable to create helm category controller")
}

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

err = (&helmrelease.ReconcileHelmRelease{
StorageClient: storageClient,
KsFactory: informerFactory.KubeSphereSharedInformerFactory(),
}).SetupWithManager(mgr)
err = (&helmrelease.ReconcileHelmRelease{
// nil interface is valid value.
StorageClient: opS3Client,
KsFactory: informerFactory.KubeSphereSharedInformerFactory(),
MultiClusterEnable: s.MultiClusterOptions.Enable,
}).SetupWithManager(mgr)

if err != nil {
klog.Fatalf("Unable to create helm release controller, error: %s", err)
}
if err != nil {
klog.Fatalf("Unable to create helm release controller, error: %s", err)
}

selector, _ := labels.Parse(s.ApplicationSelector)
Expand Down
2 changes: 1 addition & 1 deletion config/crds/application.kubesphere.io_helmrepos.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/application/v1alpha1/helmrepo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type HelmRepoStatus struct {
// +kubebuilder:resource:scope=Cluster,path=helmrepos,shortName=hrepo
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="name",type=string,JSONPath=`.spec.name`
// +kubebuilder:printcolumn:name="Workspace",type=string,JSONPath=`.metadata.labels.kubesphere\\.io/workspace`
// +kubebuilder:printcolumn:name="Workspace",type="string",JSONPath=".metadata.labels.kubesphere\\.io/workspace"
// +kubebuilder:printcolumn:name="url",type=string,JSONPath=`.spec.url`
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (conf *Config) ToMap() map[string]bool {
if conf.OpenPitrixOptions == nil {
result["openpitrix.appstore"] = false
} else {
result["openpitrix.appstore"] = conf.OpenPitrixOptions.AppStoreConfIsEmpty()
result["openpitrix.appstore"] = !conf.OpenPitrixOptions.AppStoreConfIsEmpty()
}
continue
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/controller/openpitrix/helmrelease/get_chart_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2019 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package helmrelease

import (
"context"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
"kubesphere.io/kubesphere/pkg/apis/application/v1alpha1"
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix/helmrepoindex"
"path"
"strings"
)

func (r *ReconcileHelmRelease) GetChartData(rls *v1alpha1.HelmRelease) (chartName string, chartData []byte, err error) {
if rls.Spec.RepoId != "" && rls.Spec.RepoId != v1alpha1.AppStoreRepoId {
// load chart data from helm repo
repo := v1alpha1.HelmRepo{}
err := r.Get(context.TODO(), types.NamespacedName{Name: rls.Spec.RepoId}, &repo)
if err != nil {
klog.Errorf("get helm repo %s failed, error: %v", rls.Spec.RepoId, err)
return chartName, chartData, ErrGetRepoFailed
}

index, err := helmrepoindex.ByteArrayToSavedIndex([]byte(repo.Status.Data))

if version := index.GetApplicationVersion(rls.Spec.ApplicationId, rls.Spec.ApplicationVersionId); version != nil {
url := version.Spec.URLs[0]
if !(strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "s3://")) {
url = repo.Spec.Url + "/" + url
}
buf, err := helmrepoindex.LoadChart(context.TODO(), url, &repo.Spec.Credential)
if err != nil {
klog.Infof("load chart failed, error: %s", err)
return chartName, chartData, ErrLoadChartFailed
}
chartData = buf.Bytes()
chartName = version.Name
} else {
klog.Errorf("get app version: %s failed", rls.Spec.ApplicationVersionId)
return chartName, chartData, ErrGetAppVersionFailed
}
} else {
// load chart data from helm application version
appVersion := &v1alpha1.HelmApplicationVersion{}
err = r.Get(context.TODO(), types.NamespacedName{Name: rls.Spec.ApplicationVersionId}, appVersion)
if err != nil {
klog.Errorf("get app version %s failed, error: %v", rls.Spec.ApplicationVersionId, err)
return chartName, chartData, ErrGetAppVersionFailed
}

if r.StorageClient == nil {
return "", nil, ErrS3Config
}
chartData, err = r.StorageClient.Read(path.Join(appVersion.GetWorkspace(), appVersion.Name))
if err != nil {
klog.Errorf("load chart from storage failed, error: %s", err)
return chartName, chartData, ErrLoadChartFromStorageFailed
}

chartName = appVersion.GetTrueName()
}
return
}
Loading

0 comments on commit 0a40cfd

Please sign in to comment.