fix cannot sync trait without definitionRef

Signed-off-by: roy wang <seiwy2010@gmail.com>
This commit is contained in:
roy wang
2021-02-03 20:29:11 +09:00
committed by roywang
parent fb15b43914
commit 2375e019bd
4 changed files with 57 additions and 15 deletions
+43 -6
View File
@@ -17,6 +17,11 @@ var (
URL: "https://github.com/oam-dev/kubevela/tree/master/pkg/plugins/testdata",
}
websvcCapability = types.Capability{
Name: "webservice.testapps",
Type: types.TypeWorkload,
}
scaleCapability = types.Capability{
Name: "scaler",
Type: types.TypeTrait,
@@ -41,9 +46,8 @@ var _ = ginkgo.Describe("Capability", func() {
cli := fmt.Sprintf("vela cap center config %s %s", capabilityCenterBasic.Name, capabilityCenterBasic.URL)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput1 := fmt.Sprintf("Successfully configured capability center: %s, start to sync from remote", capabilityCenterBasic.Name)
expectedOutput1 := fmt.Sprintf("Successfully configured capability center %s and sync from remote", capabilityCenterBasic.Name)
gomega.Expect(output).To(gomega.ContainSubstring(expectedOutput1))
gomega.Expect(output).To(gomega.ContainSubstring("sync finished"))
})
ginkgo.It("list capability centers", func() {
@@ -58,8 +62,18 @@ var _ = ginkgo.Describe("Capability", func() {
})
ginkgo.Context("capability", func() {
ginkgo.It("install a capability to cluster", func() {
cli := fmt.Sprintf("vela cap add %s/%s", capabilityCenterBasic.Name, scaleCapability.Name)
ginkgo.It("install a workload capability to cluster", func() {
cli := fmt.Sprintf("vela cap install %s/%s", capabilityCenterBasic.Name, websvcCapability.Name)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedSubStr1 := fmt.Sprintf("Installing %s capability", websvcCapability.Type)
expectedSubStr2 := fmt.Sprintf("Successfully installed capability %s from %s", websvcCapability.Name, capabilityCenterBasic.Name)
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr1))
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr2))
})
ginkgo.It("install a trait capability to cluster", func() {
cli := fmt.Sprintf("vela cap install %s/%s", capabilityCenterBasic.Name, scaleCapability.Name)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedSubStr1 := fmt.Sprintf("Installing %s capability", scaleCapability.Type)
@@ -68,8 +82,8 @@ var _ = ginkgo.Describe("Capability", func() {
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr2))
})
ginkgo.It("install a trait without definition reference to cluster", func() {
cli := fmt.Sprintf("vela cap add %s/%s", capabilityCenterBasic.Name, ingressCapability.Name)
ginkgo.It("install a trait capability without definition reference to cluster", func() {
cli := fmt.Sprintf("vela cap install %s/%s", capabilityCenterBasic.Name, ingressCapability.Name)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedSubStr1 := fmt.Sprintf("Installing %s capability", ingressCapability.Type)
@@ -84,11 +98,34 @@ var _ = ginkgo.Describe("Capability", func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring("CENTER"))
gomega.Expect(output).To(gomega.ContainSubstring(websvcCapability.Name))
gomega.Expect(output).To(gomega.ContainSubstring(ingressCapability.Name))
gomega.Expect(output).To(gomega.ContainSubstring(scaleCapability.Name))
gomega.Expect(output).To(gomega.ContainSubstring(routeCapability.Name))
gomega.Expect(output).To(gomega.ContainSubstring("installed"))
})
ginkgo.It("uninstall a workload capability from cluster", func() {
cli := fmt.Sprintf("vela cap uninstall %s", websvcCapability.Name)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedSubStr := fmt.Sprintf("Successfully uninstalled capability %s", websvcCapability.Name)
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr))
})
ginkgo.It("uninstall a trait capability from cluster", func() {
cli := fmt.Sprintf("vela cap uninstall %s", ingressCapability.Name)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedSubStr := fmt.Sprintf("Successfully uninstalled capability %s", ingressCapability.Name)
gomega.Expect(output).To(gomega.ContainSubstring(expectedSubStr))
// unstall other installed test capability
cli = fmt.Sprintf("vela cap uninstall %s", scaleCapability.Name)
_, err = e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})
ginkgo.It("delete a capability center", func() {
cli := fmt.Sprintf("vela cap center remove %s", capabilityCenterBasic.Name)
output, err := e2e.Exec(cli)
+1
View File
@@ -226,6 +226,7 @@ func NewCapCenterRemoveCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func listCapCenters(ioStreams cmdutil.IOStreams) error {
table := newUITable()
table.MaxColWidth = 80
table.AddRow("NAME", "ADDRESS")
capabilityCenterList, err := serverlib.ListCapabilityCenters()
if err != nil {
+2 -2
View File
@@ -247,9 +247,9 @@ func (g *GithubCenter) SyncCapabilityFromCenter() error {
continue
}
//nolint:gosec
err = ioutil.WriteFile(filepath.Join(repoDir, tmp.CrdName+".yaml"), data, 0644)
err = ioutil.WriteFile(filepath.Join(repoDir, tmp.Name+".yaml"), data, 0644)
if err != nil {
fmt.Printf("write definition %s to %s err %v\n", tmp.CrdName+".yaml", repoDir, err)
fmt.Printf("write definition %s to %s err %v\n", tmp.Name+".yaml", repoDir, err)
continue
}
success++
+11 -7
View File
@@ -91,9 +91,9 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
switch tp.Type {
case types.TypeWorkload:
var wd v1alpha2.WorkloadDefinition
workloadData, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.CrdName+".yaml")))
workloadData, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
if err != nil {
return nil
return err
}
if err = yaml.Unmarshal(workloadData, &wd); err != nil {
return err
@@ -119,9 +119,9 @@ func InstallCapability(client client.Client, mapper discoverymapper.DiscoveryMap
}
case types.TypeTrait:
var td v1alpha2.TraitDefinition
traitdata, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.CrdName+".yaml")))
traitdata, err := ioutil.ReadFile(filepath.Clean(filepath.Join(repoDir, tp.Name+".yaml")))
if err != nil {
return nil
return err
}
if err = yaml.Unmarshal(traitdata, &td); err != nil {
return err
@@ -303,13 +303,17 @@ func uninstallCap(client client.Client, cap types.Capability, ioStreams cmdutil.
capdir, _ := system.GetCapabilityDir()
switch cap.Type {
case types.TypeTrait:
return os.Remove(filepath.Join(capdir, "traits", cap.Name))
if err := os.Remove(filepath.Join(capdir, "traits", cap.Name)); err != nil {
return err
}
case types.TypeWorkload:
return os.Remove(filepath.Join(capdir, "workloads", cap.Name))
if err := os.Remove(filepath.Join(capdir, "workloads", cap.Name)); err != nil {
return err
}
case types.TypeScope:
// TODO(wonderflow): add scope remove here.
}
ioStreams.Infof("%s removed successfully", cap.Name)
ioStreams.Infof("Successfully uninstalled capability %s", cap.Name)
return nil
}