Skip to content

Commit

Permalink
Audo deploy foundation agent
Browse files Browse the repository at this point in the history
  • Loading branch information
qiujian16 committed Sep 22, 2021
1 parent 5373a6b commit ace03c9
Show file tree
Hide file tree
Showing 25 changed files with 412 additions and 80 deletions.
12 changes: 1 addition & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,9 @@ deploy-foundation-webhook: ensure-kustomize
$(KUSTOMIZE) build deploy/foundation/hub/resources/webhook | $(KUBECTL) apply -f -
mv deploy/foundation/hub/resources/webhook/kustomization.yaml.tmp deploy/foundation/hub/resources/webhook/kustomization.yaml

deploy-foundation-agent: ensure-kustomize
cp deploy/foundation/klusterlet/kustomization.yaml deploy/foundation/klusterlet/kustomization.yaml.tmp
cd deploy/foundation/klusterlet && ../../../$(KUSTOMIZE) edit set image klusterlet-addon-workmgr=$(FOUNDATION_IMAGE_NAME)
cd deploy/foundation/klusterlet && ../../../$(KUSTOMIZE) edit set namespace $(MANAGED_CLUSTER_NAME)
$(KUSTOMIZE) build deploy/foundation/klusterlet | $(KUBECTL) apply -f -
mv deploy/foundation/klusterlet/kustomization.yaml.tmp deploy/foundation/klusterlet/kustomization.yaml

clean-foundation-hub:
$(KUBECTL) delete -k deploy/foundation/hub

clean-foundation-agent:
$(KUBECTL) delete -k deploy/foundation/klusterlet

clean-foundation-webhook:
$(KUBECTL) delete -k deploy/foundation/hub/resources/webhook

Expand All @@ -97,7 +87,7 @@ clean-deploy: clean-foundation-agent clean-foundation-webhook clean-foundation-h
build-e2e:
go test -c ./test/e2e

test-e2e: build-e2e deploy-hub deploy-klusterlet deploy-foundation-hub deploy-foundation-webhook deploy-foundation-agent
test-e2e: build-e2e deploy-hub deploy-klusterlet deploy-foundation-hub deploy-foundation-webhook
deploy/foundation/scripts/install-check.sh
./e2e.test -test.v -ginkgo.v

Expand Down
40 changes: 22 additions & 18 deletions cmd/controller/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ import (

// ControllerRunOptions for the hcm controller.
type ControllerRunOptions struct {
KubeConfig string
CAFile string
LogCertSecret string
EnableInventory bool
EnableLeaderElection bool
EnableAddonDeploy bool
AddonImage string
QPS float32
Burst int
KubeConfig string
CAFile string
LogCertSecret string
EnableInventory bool
EnableLeaderElection bool
EnableAddonDeploy bool
AddonImage string
AddonInstallNamespace string
QPS float32
Burst int
}

// NewControllerRunOptions creates a new ServerRunOptions object with default values.
func NewControllerRunOptions() *ControllerRunOptions {
return &ControllerRunOptions{
KubeConfig: "",
CAFile: "/var/run/agent/ca.crt",
LogCertSecret: "ocm-klusterlet-self-signed-secrets",
EnableInventory: true,
EnableLeaderElection: true,
EnableAddonDeploy: false,
QPS: 100.0,
Burst: 200,
AddonImage: "quay.io/open-cluster-management/multicloud-manager:latest",
KubeConfig: "",
CAFile: "/var/run/agent/ca.crt",
LogCertSecret: "ocm-klusterlet-self-signed-secrets",
EnableInventory: true,
EnableLeaderElection: true,
EnableAddonDeploy: false,
QPS: 100.0,
Burst: 200,
AddonImage: "quay.io/open-cluster-management/multicloud-manager:latest",
AddonInstallNamespace: "open-cluster-management-agent-addon",
}
}

Expand All @@ -51,6 +53,8 @@ func (o *ControllerRunOptions) AddFlags(fs *pflag.FlagSet) {
"Enable deploy addon agent.")
fs.StringVar(&o.AddonImage, "agent-addon-image", o.AddonImage,
"image of the addon agent to deploy.")
fs.StringVar(&o.AddonInstallNamespace, "agent-addon-install-namespace", o.AddonInstallNamespace,
"namespace on the managed cluster for the addon agent to install.")
fs.Float32Var(&o.QPS, "max-qps", o.QPS,
"Maximum QPS to the hub server from this controller.")
fs.IntVar(&o.Burst, "max-burst", o.Burst,
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func Run(o *options.ControllerRunOptions, ctx context.Context) error {
return err
}
if o.EnableAddonDeploy {
addonMgr.AddAgent(addon.NewAgent(kubeClient, "work-manager", o.AddonImage))
addonMgr.AddAgent(addon.NewAgent(kubeClient, "work-manager", o.AddonImage, o.AddonInstallNamespace))
}

// Setup reconciler
Expand Down
1 change: 1 addition & 0 deletions deploy/foundation/hub/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resources:
- resources/controller.yaml
- resources/clusterviewv1-apiservice.yaml
- resources/clusterviewv1alpha1-apiservice.yaml
- resources/clustermanagementaddon.yaml

images:
- name: ocm-controller
Expand Down
8 changes: 8 additions & 0 deletions deploy/foundation/hub/resources/clustermanagementaddon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: addon.open-cluster-management.io/v1alpha1
kind: ClusterManagementAddOn
metadata:
name: work-manager
spec:
addOnMeta:
displayName: work-manager
description: "work-manager provides action, view and rbac settings"
5 changes: 4 additions & 1 deletion deploy/foundation/hub/resources/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ rules:
resources: ["managedclusteraddons/finalizers"]
verbs: ["update"]
- apiGroups: ["addon.open-cluster-management.io"]
resources: ["managedclusteraddons", "clustermanagementaddons"]
resources: ["clustermanagementaddons"]
verbs: ["get", "list", "watch"]
- apiGroups: ["addon.open-cluster-management.io"]
resources: ["managedclusteraddons"]
verbs: ["get", "list", "watch", "create", "update"]
- apiGroups: ["addon.open-cluster-management.io"]
resources: ["managedclusteraddons/status"]
verbs: ["update", "patch"]
Expand Down
11 changes: 0 additions & 11 deletions deploy/foundation/klusterlet/kustomization.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions deploy/foundation/klusterlet/resources/agent-addon.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/foundation/scripts/install-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for i in {1..7}; do
RUNNING_POD=$((RUNNING_POD+proxyserver))
webhook=$($KUBECTL -n open-cluster-management get pods | grep ocm-webhook | grep -c "Running")
RUNNING_POD=$((RUNNING_POD+webhook))
agent=$($KUBECTL -n open-cluster-management-agent get pods | grep klusterlet-addon-workmgr | grep -c "Running")
agent=$($KUBECTL -n open-cluster-management-agent-addon get pods | grep klusterlet-addon-workmgr | grep -c "Running")
RUNNING_POD=$((RUNNING_POD+agent))

if [ "${RUNNING_POD}" -eq 4 ]; then
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ require (
k8s.io/klog/v2 v2.9.0
k8s.io/kube-aggregator v0.21.2
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
open-cluster-management.io/addon-framework v0.0.0-20210803032803-58eac513499e
open-cluster-management.io/addon-framework v0.0.0-20210917064257-293df7afd295
open-cluster-management.io/api v0.0.0-20210908005819-815ac23c7308
sigs.k8s.io/controller-runtime v0.9.3-0.20210709165254-650ea59f19cc
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,7 @@ k8s.io/apiserver v0.19.0/go.mod h1:XvzqavYj73931x7FLtyagh8WibHpePJ1QwWrSJs2CLk=
k8s.io/apiserver v0.19.1/go.mod h1:iRxYIjA0X2XEyoW8KslN4gDhasfH4bWcjj6ckVeZX28=
k8s.io/apiserver v0.19.4/go.mod h1:X8WRHCR1UGZDd7HpV0QDc1h/6VbbpAeAGyxSh8yzZXw=
k8s.io/apiserver v0.20.2/go.mod h1:2nKd93WyMhZx4Hp3RfgH2K5PhwyTrprrkWYnI7id7jA=
k8s.io/apiserver v0.21.1/go.mod h1:nLLYZvMWn35glJ4/FZRhzLG/3MPxAaZTgV4FJZdr+tY=
k8s.io/apiserver v0.21.2 h1:vfGLD8biFXHzbcIEXyW3652lDwkV8tZEFJAaS2iuJlw=
k8s.io/apiserver v0.21.2/go.mod h1:lN4yBoGyiNT7SC1dmNk0ue6a5Wi6O3SWOIw91TsucQw=
k8s.io/autoscaler v0.0.0-20190607113959-1b4f1855cb8e/go.mod h1:QEXezc9uKPT91dwqhSJq3GNI3B1HxFRQHiku9kmrsSA=
Expand Down Expand Up @@ -2633,8 +2634,8 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jC
mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34/go.mod h1:H6SUd1XjIs+qQCyskXg5OFSrilMRUkD8ePJpHKDPaeY=
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7/go.mod h1:HGC5lll35J70Y5v7vCGb9oLhHoScFwkHDJm/05RdSTc=
open-cluster-management.io/addon-framework v0.0.0-20210803032803-58eac513499e h1:DxNKxwhT9kzyHM1o3cRp5q2xODXt9+wXT5wK/E57BIg=
open-cluster-management.io/addon-framework v0.0.0-20210803032803-58eac513499e/go.mod h1:csWpIbCe2NVVtCFlLbfgvk7XRjYSwZDRqLTFU10KR4A=
open-cluster-management.io/addon-framework v0.0.0-20210917064257-293df7afd295 h1:FFGv87383j28j/ByAhoLLXnAkMO04NXAJSjsuVZ94sk=
open-cluster-management.io/addon-framework v0.0.0-20210917064257-293df7afd295/go.mod h1:upMV+97asubQnQ1WY3W67nd4pIReZNR4beVkABXFjE0=
open-cluster-management.io/api v0.0.0-20210607023841-cd164385e2bb/go.mod h1:9qiA5h/8kvPQnJEOlAPHVjRO9a1jCmDhGzvgMBvXEaE=
open-cluster-management.io/api v0.0.0-20210908005819-815ac23c7308 h1:itWWudWVTqviZ2H2Arb1yTQ7NMUSPVDmWiVOpXiblOM=
open-cluster-management.io/api v0.0.0-20210908005819-815ac23c7308/go.mod h1:9qiA5h/8kvPQnJEOlAPHVjRO9a1jCmDhGzvgMBvXEaE=
Expand All @@ -2645,6 +2646,7 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.9/go.mod h1:dzAXnQbTRyDlZPJX2SUPEqvnB+j7AJjtlox7PEwigU0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.19 h1:0jaDAAxtqIrrqas4vtTqxct4xS5kHfRNycTRLTyJmVM=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.19/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/controller-runtime v0.0.0-20190520212815-96b67f231945/go.mod h1:TSH2R0nSz4WAlUUlNnOFcOR/VUhfwBLlmtq2X6AiQCA=
Expand Down
24 changes: 13 additions & 11 deletions pkg/addon/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ func init() {
}

const (
clusterRoleName = "managed-cluster-workmgr"
roleBindingName = "managed-cluster-workmgr"
defaultInstallationNamespace = "open-cluster-management-agent-addon"
clusterRoleName = "managed-cluster-workmgr"
roleBindingName = "managed-cluster-workmgr"
)

var agentDeploymentFiles = []string{
Expand All @@ -48,16 +47,18 @@ var agentDeploymentFiles = []string{
var manifestFiles embed.FS

type foundationAgent struct {
kubeClient kubernetes.Interface
addonName string
imageName string
kubeClient kubernetes.Interface
addonName string
imageName string
installNamespace string
}

func NewAgent(kubeClient kubernetes.Interface, addonName, imageName string) *foundationAgent {
func NewAgent(kubeClient kubernetes.Interface, addonName, imageName, installNamespace string) *foundationAgent {
return &foundationAgent{
kubeClient: kubeClient,
addonName: addonName,
imageName: imageName,
kubeClient: kubeClient,
addonName: addonName,
imageName: imageName,
installNamespace: installNamespace,
}
}

Expand All @@ -67,7 +68,7 @@ func (f *foundationAgent) Manifests(cluster *clusterv1.ManagedCluster, addon *ad
// using open-cluster-management-agent-addon namespace as default namespace.
installNamespace := addon.Spec.InstallNamespace
if len(installNamespace) == 0 {
installNamespace = defaultInstallationNamespace
installNamespace = f.installNamespace
}

manifestConfig := struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func (f *foundationAgent) GetAgentAddonOptions() agent.AgentAddonOptions {
return f.createOrUpdateRoleBinding(cluster.Name)
},
},
InstallStrategy: agent.InstallAllStrategy(f.installNamespace),
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/addon/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func TestManifest(t *testing.T) {
}{
{
name: "no install namespace",
agent: NewAgent(nil, "work-mgr", "test"),
agent: NewAgent(nil, "work-mgr", "test", "open-cluster-management-agent-addon"),
cluster: newCluster("cluster1"),
addon: newAddon("work-mgr", "cluster1", ""),
expectedNamespace: defaultInstallationNamespace,
expectedNamespace: "open-cluster-management-agent-addon",
expectedImage: "test",
},
{
name: "no install namespace",
agent: NewAgent(nil, "work-mgr", "test"),
agent: NewAgent(nil, "work-mgr", "test", "open-cluster-management-agent-addon"),
cluster: newCluster("cluster1"),
addon: newAddon("work-mgr", "cluster1", "test"),
expectedNamespace: "test",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestCreateOrUpdateRoleBinding(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
kubeClient := fakekube.NewSimpleClientset(test.initObjects...)
agent := NewAgent(kubeClient, "work-mgr", "test")
agent := NewAgent(kubeClient, "work-mgr", "test", "open-cluster-management-agent-addon")
err := agent.createOrUpdateRoleBinding(test.clusterName)
if err != nil {
t.Errorf("createOrUpdateRoleBinding expected no error, but got %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/addon/manifests/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: klusterlet-addon-workmgr-sa
namespace: open-cluster-management-agent
namespace: {{ .Namespace }}
2 changes: 1 addition & 1 deletion pkg/addon/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
- "--hub-kubeconfig=/var/run/hub/kubeconfig"
- "--cluster-name={{ .ClusterName }}"
- "--port=4443"
- "--agent-address=klusterlet-addon-workmgr.open-cluster-management-agent.svc"
- "--agent-address=klusterlet-addon-workmgr.{{ .Namespace }}.svc"
- "--agent-port=443"
- "--lease-duration=5"
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var (
podNamespace = "open-cluster-management-agent"
podNamespace = "open-cluster-management-agent-addon"
managedClusterAddOnName = "work-manager"
)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

var _ = ginkgo.Describe("Testing Pod log", func() {
podNamespace := "open-cluster-management-agent"
podNamespace := "open-cluster-management-agent-addon"
var podName string
var containerName string
var restClient *rest.RESTClient
Expand Down
4 changes: 3 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1147,12 +1147,14 @@ k8s.io/utils/net
k8s.io/utils/path
k8s.io/utils/pointer
k8s.io/utils/trace
# open-cluster-management.io/addon-framework v0.0.0-20210803032803-58eac513499e
# open-cluster-management.io/addon-framework v0.0.0-20210917064257-293df7afd295
## explicit
open-cluster-management.io/addon-framework/pkg/addonmanager
open-cluster-management.io/addon-framework/pkg/addonmanager/constants
open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/addoninstall
open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/agentdeploy
open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/certificate
open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/clustermanagement
open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/registration
open-cluster-management.io/addon-framework/pkg/agent
open-cluster-management.io/addon-framework/pkg/lease
Expand Down
Loading

0 comments on commit ace03c9

Please sign in to comment.