Skip to content

Commit 346c385

Browse files
authored
Bring back application-manager addon and remove argocd-addon by reverting main branch commit 3d8291d (#490)
Signed-off-by: Mike Ng <[email protected]>
1 parent 6a21472 commit 346c385

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2338
-171
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,22 @@ Clean up the multicluster hub control plane and other initialized resources on t
127127

128128
Install specific built-in add-on(s) to the hub cluster.
129129

130-
`clusteradm install hub-addon --names argocd`
130+
`clusteradm install hub-addon --names application-manager`
131131

132132
`clusteradm install hub-addon --names governance-policy-framework`
133133

134134
### enable addons
135135

136136
Enable specific add-on(s) agent deployment to the given managed clusters of the specified namespace
137137

138-
`clusteradm addon enable --names argocd --namespace <namespace> --clusters <cluster1>,<cluster2>,....`
138+
`clusteradm addon enable --names application-manager --namespace <namespace> --clusters <cluster1>,<cluster2>,....`
139139

140140
`clusteradm addon enable --names governance-policy-framework --namespace <namespace> --clusters <cluster1>,<cluster2>,....`
141141

142142
`clusteradm addon enable --names config-policy-controller --namespace <namespace> --clusters <cluster1>,<cluster2>,....`
143143

144144
### create sample application
145145

146-
Create and deploy a sample Argo CD ApplicationSet
146+
Create and Deploy a Sample Subscription Application
147147

148-
`clusteradm create sampleapp sample-appset`
148+
`clusteradm create sampleapp sampleapp1`

pkg/cmd/addon/disable/cmd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
)
1313

1414
var example = `
15-
# Disable argocd addon on specified clusters
16-
%[1]s addon disable --names argocd --clusters cluster1,cluster2
17-
# Disable argocd addon on all clusters
18-
%[1]s addon disable --names argocd --all-clusters
19-
# Disable argocd addon to the given managed clusters in the specified namespace
20-
%[1]s addon disable --names argocd --namespace <namespace> --clusters <cluster1>
15+
# Disable application-manager addon on specified clusters
16+
%[1]s addon disable --names application-manager --clusters cluster1,cluster2
17+
# Disable application-manager addon on all clusters
18+
%[1]s addon disable --names application-manager --all-clusters
19+
# Disable application-manager addon to the given managed clusters in the specified namespace
20+
%[1]s addon disable --names application-manager --namespace <namespace> --clusters <cluster1>
2121
2222
## Policy Framework
2323

pkg/cmd/addon/disable/exec_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var _ = ginkgo.Describe("addon disable", func() {
2323
var cluster2Name string
2424
var err error
2525

26-
appMgrAddonName := "argocd"
26+
appMgrAddonName := "application-manager"
2727

2828
ginkgo.BeforeEach(func() {
2929
cluster1Name = fmt.Sprintf("cluster-%s", rand.String(5))
@@ -71,7 +71,7 @@ var _ = ginkgo.Describe("addon disable", func() {
7171

7272
ginkgo.Context("runWithClient", func() {
7373

74-
ginkgo.It("Should disable argocd ManagedClusterAddOn in ManagedCluster namespace successfully", func() {
74+
ginkgo.It("Should disable application-manager ManagedClusterAddOn in ManagedCluster namespace successfully", func() {
7575
assertCreatingClusters(cluster1Name)
7676

7777
addons := []string{appMgrAddonName}
@@ -86,7 +86,7 @@ var _ = ginkgo.Describe("addon disable", func() {
8686
gomega.Expect(err).ToNot(gomega.HaveOccurred())
8787
})
8888

89-
ginkgo.It("Should disable argocd ManagedClusterAddOns in each ManagedCluster namespace successfully", func() {
89+
ginkgo.It("Should disable application-manager ManagedClusterAddOns in each ManagedCluster namespace successfully", func() {
9090
assertCreatingClusters(cluster1Name)
9191
assertCreatingClusters(cluster2Name)
9292

pkg/cmd/addon/enable/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
var example = `
1515
## Application Manager
1616
17-
# Enable argocd addon on the given managed clusters in the specified namespace
18-
%[1]s addon enable --names argocd --namespace namespace --clusters cluster1,cluster2
19-
# Enable argocd addon for specified clusters
20-
%[1]s addon enable --names argocd --clusters cluster1,cluster2
17+
# Enable application-manager addon on the given managed clusters in the specified namespace
18+
%[1]s addon enable --names application-manager --namespace namespace --clusters cluster1,cluster2
19+
# Enable application-manager addon for specified clusters
20+
%[1]s addon enable --names application-manager --clusters cluster1,cluster2
2121
2222
## Policy Framework
2323

pkg/cmd/addon/enable/exec_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _ = ginkgo.Describe("addon enable", func() {
2222

2323
// Array of addons to check
2424
var addons = []string{
25-
"argocd",
25+
"application-manager",
2626
"governance-policy-framework",
2727
"config-policy-controller",
2828
}

pkg/cmd/create/sampleapp/cmd.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
var example = `
1616
# Create a sample app
1717
%[1]s create sampleapp sampleapp1
18+
# Create a sample app on specified namespace
19+
%[1]s create sampleapp sampleapp1 --namespace namespace1
1820
`
1921

2022
// NewCmd...
@@ -23,8 +25,8 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
2325

2426
cmd := &cobra.Command{
2527
Use: "sampleapp",
26-
Short: "Create a sample Argo CD ApplicationSet",
27-
Long: "Create a sample Argo CD ApplicationSet",
28+
Short: "Create a sample app",
29+
Long: "Create a sample app, by generating Helm ngix deployment yamls",
2830
Example: fmt.Sprintf(example, clusteradmhelpers.GetExampleHeader()),
2931
SilenceUsage: true,
3032
PreRunE: func(c *cobra.Command, args []string) error {
@@ -48,6 +50,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
4850
}
4951

5052
cmd.Flags().StringVar(&o.OutputFile, "output-file", "", "The generated resources will be copied in the specified file")
53+
cmd.Flags().StringVarP(&o.Namespace, "namespace", "n", "default", "Specified namespace to deploy sample app")
5154

5255
return cmd
5356
}

pkg/cmd/create/sampleapp/exec.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package sampleapp
44

55
import (
6+
"context"
67
"errors"
78
"fmt"
89
"os"
@@ -12,13 +13,17 @@ import (
1213
"open-cluster-management.io/clusteradm/pkg/helpers/reader"
1314

1415
"github.com/spf13/cobra"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1517
clusterclientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
1618
"open-cluster-management.io/clusteradm/pkg/cmd/create/sampleapp/scenario"
1719
)
1820

1921
const (
2022
defaultSampleAppName = "sampleapp"
2123
pathToAppManifests = "scenario/sampleapp"
24+
clusterSetLabel = "cluster.open-cluster-management.io/clusterset"
25+
placementLabel = "placement"
26+
placementLabelValue = "sampleapp"
2227
)
2328

2429
func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
@@ -62,12 +67,48 @@ func (o *Options) Run() (err error) {
6267

6368
func (o *Options) runWithClient(clusterClient clusterclientset.Interface, dryRun bool) error {
6469

70+
// Label all managed clusters with clusterset and placement labels
71+
err := o.checkManagedClusterBinding(clusterClient, dryRun)
72+
if err != nil {
73+
return err
74+
}
75+
6576
// Apply sample application manifest to hub cluster
66-
err := o.deployApp()
77+
err = o.deployApp()
78+
if err != nil {
79+
return err
80+
}
81+
82+
return nil
83+
}
84+
85+
func (o *Options) checkManagedClusterBinding(clusterClient clusterclientset.Interface, dryRun bool) error {
86+
87+
// Skip if dryRun
88+
if dryRun {
89+
return nil
90+
}
91+
92+
// Get managed clusters
93+
clusters, err := clusterClient.ClusterV1().ManagedClusters().List(context.TODO(), metav1.ListOptions{})
6794
if err != nil {
6895
return err
6996
}
7097

98+
// Check for binding labels in managed clusters
99+
for _, cluster := range clusters.Items {
100+
managedCluster, err := clusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), cluster.Name, metav1.GetOptions{})
101+
if err != nil {
102+
return err
103+
}
104+
if cs, ok := managedCluster.Labels[clusterSetLabel]; !ok || (cs != fmt.Sprintf("app-%s", o.SampleAppName)) {
105+
fmt.Fprintf(o.Streams.Out, "[WARNING] Label \"%s=%s\" has not been found in ManagedCluster %s, could not establish binding.\n", clusterSetLabel, fmt.Sprintf("app-%s", o.SampleAppName), cluster.Name)
106+
}
107+
if p, ok := managedCluster.Labels[placementLabel]; !ok || (p != placementLabelValue) {
108+
fmt.Fprintf(o.Streams.Out, "[WARNING] Label \"%s=%s\" has not been found in ManagedCluster %s, could not establish binding.\n", placementLabel, placementLabelValue, cluster.Name)
109+
}
110+
}
111+
71112
return nil
72113
}
73114

0 commit comments

Comments
 (0)