Signed-off-by: LiHui <andrewli@yunify.com> delete helm repo, release and app Signed-off-by: LiHui <andrewli@yunify.com> Fix Dockerfile Signed-off-by: LiHui <andrewli@yunify.com> add unit test for category controller Signed-off-by: LiHui <andrewli@yunify.com> resource api Signed-off-by: LiHui <andrewli@yunify.com> miscellaneous Signed-off-by: LiHui <andrewli@yunify.com> resource api Signed-off-by: LiHui <andrewli@yunify.com> add s3 repo indx Signed-off-by: LiHui <andrewli@yunify.com> attachment api Signed-off-by: LiHui <andrewli@yunify.com> repo controller test Signed-off-by: LiHui <andrewli@yunify.com> application controller test Signed-off-by: LiHui <andrewli@yunify.com> release metric Signed-off-by: LiHui <andrewli@yunify.com> helm release controller test Signed-off-by: LiHui <andrewli@yunify.com> move constants to /pkg/apis/application Signed-off-by: LiHui <andrewli@yunify.com> remove unused code Signed-off-by: LiHui <andrewli@yunify.com> add license header Signed-off-by: LiHui <andrewli@yunify.com> Fix bugs Signed-off-by: LiHui <andrewli@yunify.com> cluster cluent Signed-off-by: LiHui <andrewli@yunify.com> format code Signed-off-by: LiHui <andrewli@yunify.com> move workspace,cluster from spec to labels Signed-off-by: LiHui <andrewli@yunify.com> add license header Signed-off-by: LiHui <andrewli@yunify.com> openpitrix test Signed-off-by: LiHui <andrewli@yunify.com> add worksapce labels for app in appstore Signed-off-by: LiHui <andrewli@yunify.com>
128 lines
3.7 KiB
Go
128 lines
3.7 KiB
Go
/*
|
|
Copyright 2020 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 openpitrix
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"github.com/go-openapi/strfmt"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/klog"
|
|
"kubesphere.io/kubesphere/pkg/server/params"
|
|
"testing"
|
|
)
|
|
|
|
func TestOpenPitrixRelease(t *testing.T) {
|
|
appOperator := prepareAppOperator()
|
|
|
|
chartData, _ := base64.RawStdEncoding.DecodeString(rawChartData)
|
|
|
|
appReq := &CreateAppRequest{
|
|
Isv: testWorkspace,
|
|
Name: "test-chart",
|
|
VersionName: "0.1.0",
|
|
VersionPackage: strfmt.Base64(chartData),
|
|
}
|
|
|
|
// create app
|
|
createAppResp, err := appOperator.CreateApp(appReq)
|
|
if err != nil {
|
|
klog.Errorf("create app failed")
|
|
t.Fail()
|
|
}
|
|
|
|
// add app to indexer
|
|
apps, err := ksClient.ApplicationV1alpha1().HelmApplications().List(context.TODO(), metav1.ListOptions{})
|
|
for _, app := range apps.Items {
|
|
err := fakeInformerFactory.KubeSphereSharedInformerFactory().Application().V1alpha1().HelmApplications().
|
|
Informer().GetIndexer().Add(&app)
|
|
if err != nil {
|
|
klog.Errorf("failed to add app to indexer")
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
// add app version to indexer
|
|
appvers, err := ksClient.ApplicationV1alpha1().HelmApplicationVersions().List(context.TODO(), metav1.ListOptions{})
|
|
for _, ver := range appvers.Items {
|
|
err := fakeInformerFactory.KubeSphereSharedInformerFactory().Application().V1alpha1().HelmApplicationVersions().
|
|
Informer().GetIndexer().Add(&ver)
|
|
if err != nil {
|
|
klog.Errorf("failed to add app version to indexer")
|
|
t.Fail()
|
|
}
|
|
}
|
|
|
|
rlsOperator := newReleaseOperator(cachedReposData, fakeInformerFactory.KubernetesSharedInformerFactory(), fakeInformerFactory.KubeSphereSharedInformerFactory(), ksClient)
|
|
|
|
req := CreateClusterRequest{
|
|
Name: "test-rls",
|
|
AppId: createAppResp.AppID,
|
|
VersionId: createAppResp.VersionID,
|
|
Workspace: testWorkspace,
|
|
}
|
|
err = rlsOperator.CreateApplication(testWorkspace, "", "default", req)
|
|
|
|
if err != nil {
|
|
klog.Errorf("create release failed, error: %s", err)
|
|
t.FailNow()
|
|
}
|
|
|
|
// add app version to indexer
|
|
rls, err := ksClient.ApplicationV1alpha1().HelmReleases().List(context.TODO(), metav1.ListOptions{})
|
|
for _, item := range rls.Items {
|
|
err := fakeInformerFactory.KubeSphereSharedInformerFactory().Application().V1alpha1().HelmReleases().
|
|
Informer().GetIndexer().Add(&item)
|
|
if err != nil {
|
|
klog.Errorf("failed to add release to indexer")
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
cond := ¶ms.Conditions{Match: map[string]string{
|
|
WorkspaceLabel: testWorkspace,
|
|
}}
|
|
rlsList, err := rlsOperator.ListApplications(testWorkspace, "", "default", cond, 10, 0, "", false)
|
|
|
|
if err != nil {
|
|
klog.Errorf("failed to list release, error: %s", err)
|
|
t.FailNow()
|
|
}
|
|
|
|
var rlsId string
|
|
for _, item := range rlsList.Items {
|
|
app := item.(*Application)
|
|
rlsId = app.Cluster.ClusterId
|
|
break
|
|
}
|
|
|
|
//describe release
|
|
describeRls, err := rlsOperator.DescribeApplication(testWorkspace, "", "default", rlsId)
|
|
if err != nil {
|
|
klog.Errorf("failed to describe release, error: %s", err)
|
|
t.FailNow()
|
|
}
|
|
_ = describeRls
|
|
|
|
//delete release
|
|
err = rlsOperator.DeleteApplication(testWorkspace, "", "default", rlsId)
|
|
if err != nil {
|
|
klog.Errorf("failed to delete release, error: %s", err)
|
|
t.FailNow()
|
|
}
|
|
}
|