mirror of
https://github.com/kubevela/kubevela.git
synced 2026-03-05 11:11:28 +00:00
* Feat: show available versions and dependencies in `addon status` Also prettify output Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: show addon dependencies in `addon status` Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Style: adjust `addon status` output Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Style: remove spaces in `addon status` output Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Fix: truncate string if available versions too long if a local addon has been installed, the AVAILABLE-VERSIONS column of the registry one will not truncate. this commit fixes that. Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Perf: avoid unnecessary network requests to improve performance Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: do not display remote info for local addons Limit Description length when using `addon list` Use simpler method to get addon info Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: add tests for cli/addon limitStringLength, generateParameterString Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Fix: fix output being empty if the searched addon does not exist anywhere Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: add tests for generateAddonInfo Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: add tests for generateAddonInfo and FindWholeAddonPackagesFromRegistry Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Style: format code Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: correct unnecessarily focused tests Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Style: remove unused code blocks Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Refactor: remove unnecessary output to stdout Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: remove added registry after tests has been completed Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: new RegistryDataStore every test, to avoid panics Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: fix failing tests due to incorrect registry name Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Refactor: move logic to get addon package out of where it is supposed to get addon status Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: add test cases for secret-getting in TestGetAddonStatus Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: return error if an addon is not installed, nor does it exist in the registry Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Refactor: rename GetAddonWholePackage to GetDetailedAddon as per wonderflow Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: require --verbose option to show details in `vela addon status` Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Feat: require --verbose option to show details in `vela addon status` Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * chore: run make reviewable Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Test: fix configmap being already existed Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Fix: fix output show addon does not exist when verbose is off and an addon is not installed, but it does exist in the registry Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com> * Style: fix golangci-lint issues Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
198 lines
7.4 KiB
Go
198 lines
7.4 KiB
Go
/*
|
|
Copyright 2022 The KubeVela 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 addon
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http/httptest"
|
|
"strings"
|
|
|
|
v1 "k8s.io/api/core/v1"
|
|
"sigs.k8s.io/yaml"
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("test FindWholeAddonPackagesFromRegistry", func() {
|
|
Describe("when no registry is added, no matter what you do, it will just return error", func() {
|
|
Context("when empty addonNames and registryNames is supplied", func() {
|
|
It("should return error", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{}, []string{})
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
It("should return error", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, nil, nil)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
Context("when non-empty addonNames and registryNames is supplied", func() {
|
|
It("should return error saying ErrRegistryNotExist", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"fluxcd"}, []string{"some-registry"})
|
|
Expect(errors.Is(err, ErrRegistryNotExist)).To(BeTrue())
|
|
})
|
|
})
|
|
})
|
|
|
|
Describe("one versioned registry is added", func() {
|
|
BeforeEach(func() {
|
|
// Prepare KubeVela registry
|
|
reg := &Registry{
|
|
Name: "KubeVela",
|
|
Helm: &HelmSource{
|
|
URL: "https://addons.kubevela.net",
|
|
},
|
|
}
|
|
ds := NewRegistryDataStore(k8sClient)
|
|
Expect(ds.AddRegistry(context.Background(), *reg)).To(Succeed())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
// Clean up KubeVela registry
|
|
ds := NewRegistryDataStore(k8sClient)
|
|
Expect(ds.DeleteRegistry(context.Background(), "KubeVela")).To(Succeed())
|
|
})
|
|
|
|
Context("when empty addonNames and registryNames is supplied", func() {
|
|
It("should return error, empty addonNames are not allowed", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{}, []string{"KubeVela"})
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
It("should return error, empty addonNames are not allowed", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, nil, []string{"KubeVela"})
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("one existing addon name provided", func() {
|
|
It("should return one valid result, matching all registries", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"velaux"}, nil)
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("velaux"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
Expect(res[0].APISchema).ToNot(BeNil())
|
|
})
|
|
It("should return one valid result, matching one registry", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"velaux"}, []string{"KubeVela"})
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("velaux"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
Expect(res[0].APISchema).ToNot(BeNil())
|
|
})
|
|
})
|
|
|
|
Context("one non-existent addon name provided", func() {
|
|
It("should return error as ErrNotExist", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"non-existent-addon"}, nil)
|
|
Expect(errors.Is(err, ErrNotExist)).To(BeTrue())
|
|
Expect(res).To(BeNil())
|
|
})
|
|
})
|
|
|
|
Context("two existing addon names provided", func() {
|
|
It("should return two valid result", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"velaux", "traefik"}, nil)
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(2))
|
|
Expect(res[0].Name).To(Equal("velaux"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
Expect(res[0].APISchema).ToNot(BeNil())
|
|
Expect(res[1].Name).To(Equal("traefik"))
|
|
Expect(res[1].InstallPackage).ToNot(BeNil())
|
|
Expect(res[1].APISchema).ToNot(BeNil())
|
|
})
|
|
})
|
|
|
|
Context("one existing addon name and one non-existent addon name provided", func() {
|
|
It("should return only one valid result", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"velaux", "non-existent-addon"}, nil)
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("velaux"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
Expect(res[0].APISchema).ToNot(BeNil())
|
|
})
|
|
})
|
|
})
|
|
|
|
Describe("one non-versioned registry is added", func() {
|
|
var server *httptest.Server
|
|
BeforeEach(func() {
|
|
// Prepare local non-versioned registry
|
|
server = httptest.NewServer(ossHandler)
|
|
cm := v1.ConfigMap{}
|
|
cmYaml := strings.ReplaceAll(registryCmYaml, "TEST_SERVER_URL", server.URL)
|
|
cmYaml = strings.ReplaceAll(cmYaml, "KubeVela", "testreg")
|
|
Expect(yaml.Unmarshal([]byte(cmYaml), &cm)).Should(BeNil())
|
|
Expect(k8sClient.Update(ctx, &cm)).Should(BeNil())
|
|
})
|
|
|
|
AfterEach(func() {
|
|
server.Close()
|
|
})
|
|
|
|
Context("when empty addonNames and registryNames is supplied", func() {
|
|
It("should return error, empty addonNames are not allowed", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{}, []string{})
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
It("should return error, empty addonNames are not allowed", func() {
|
|
_, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, nil, []string{"testreg"})
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|
|
|
|
Context("one existing addon name provided", func() {
|
|
It("should return one valid result, matching all registries", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"example"}, nil)
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("example"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
})
|
|
It("should return one valid result, matching one registry", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"example"}, []string{"testreg"})
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("example"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
})
|
|
})
|
|
|
|
Context("one non-existent addon name provided", func() {
|
|
It("should return error as ErrNotExist", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"non-existent-addon"}, nil)
|
|
Expect(errors.Is(err, ErrNotExist)).To(BeTrue())
|
|
Expect(res).To(BeNil())
|
|
})
|
|
})
|
|
|
|
Context("one existing addon name and one non-existent addon name provided", func() {
|
|
It("should return only one valid result", func() {
|
|
res, err := FindWholeAddonPackagesFromRegistry(context.Background(), k8sClient, []string{"example", "non-existent-addon"}, nil)
|
|
Expect(err).To(Succeed())
|
|
Expect(res).To(HaveLen(1))
|
|
Expect(res[0].Name).To(Equal("example"))
|
|
Expect(res[0].InstallPackage).ToNot(BeNil())
|
|
})
|
|
})
|
|
})
|
|
})
|