From 93c3c04c352108434b2b9c06a14a812a026c991d Mon Sep 17 00:00:00 2001 From: lonelyCZ <531187475@qq.com> Date: Sat, 2 Apr 2022 14:46:16 +0800 Subject: [PATCH] Implement karmadactl get to support pull mode cluster Signed-off-by: lonelyCZ <531187475@qq.com> --- artifacts/agent/karmada-agent.yaml | 1 + hack/deploy-karmada-agent.sh | 5 +++++ pkg/karmadactl/get.go | 13 +------------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/artifacts/agent/karmada-agent.yaml b/artifacts/agent/karmada-agent.yaml index a4c55f6c0e2c..527d045daaaf 100644 --- a/artifacts/agent/karmada-agent.yaml +++ b/artifacts/agent/karmada-agent.yaml @@ -28,6 +28,7 @@ spec: - --karmada-kubeconfig=/etc/kubeconfig/karmada-kubeconfig - --karmada-context={{karmada_context}} - --cluster-name={{member_cluster_name}} + - --cluster-api-endpoint={{member_cluster_api_endpoint}} - --cluster-status-update-frequency=10s - --v=4 volumeMounts: diff --git a/hack/deploy-karmada-agent.sh b/hack/deploy-karmada-agent.sh index bdf6db0b80d9..5e33751d22c7 100755 --- a/hack/deploy-karmada-agent.sh +++ b/hack/deploy-karmada-agent.sh @@ -82,12 +82,17 @@ kubectl apply -f "${REPO_ROOT}/artifacts/agent/clusterrolebinding.yaml" # create secret kubectl create secret generic karmada-kubeconfig --from-file=karmada-kubeconfig="${KARMADA_APISERVER_KUBECONFIG}" -n "${KARMADA_SYSTEM_NAMESPACE}" +# extract api endpoint of member cluster +MEMBER_CLUSTER=$(kubectl config view -o jsonpath='{.contexts[?(@.name == "'${MEMBER_CLUSTER_NAME}'")].context.cluster}') +MEMBER_CLUSTER_API_ENDPOINT=$(kubectl config view -o jsonpath='{.clusters[?(@.name == "'${MEMBER_CLUSTER}'")].cluster.server}') + # deploy karmada agent TEMP_PATH=$(mktemp -d) cp "${REPO_ROOT}"/artifacts/agent/karmada-agent.yaml "${TEMP_PATH}"/karmada-agent.yaml sed -i'' -e "s/{{karmada_context}}/${KARMADA_APISERVER_CONTEXT_NAME}/g" "${TEMP_PATH}"/karmada-agent.yaml sed -i'' -e "s/{{member_cluster_name}}/${MEMBER_CLUSTER_NAME}/g" "${TEMP_PATH}"/karmada-agent.yaml sed -i'' -e "s/{{image_pull_policy}}/${AGENT_IMAGE_PULL_POLICY}/g" "${TEMP_PATH}"/karmada-agent.yaml +sed -i'' -e "s|{{member_cluster_api_endpoint}}|${MEMBER_CLUSTER_API_ENDPOINT}|g" "${TEMP_PATH}"/karmada-agent.yaml echo -e "Apply dynamic rendered deployment in ${TEMP_PATH}/karmada-agent.yaml.\n" kubectl apply -f "${TEMP_PATH}"/karmada-agent.yaml diff --git a/pkg/karmadactl/get.go b/pkg/karmadactl/get.go index 3e2c800c0715..9a5821dd61fa 100644 --- a/pkg/karmadactl/get.go +++ b/pkg/karmadactl/get.go @@ -52,8 +52,7 @@ var ( {Name: "ADOPTION", Type: "string", Format: "", Priority: 0}, } - noPushModeMessage = "The karmadactl get command now only supports Push mode, [ %s ] are not push mode\n" - getShort = `Display one or many resources` + getShort = `Display one or many resources` ) // NewCmdGet New get command @@ -225,23 +224,13 @@ func (g *CommandGetOptions) Run(karmadaConfig KarmadaConfig, cmd *cobra.Command, return err } - var noPushModeCluster []string wg.Add(len(g.Clusters)) for idx := range g.Clusters { - if clusterInfos[g.Clusters[idx]].ClusterSyncMode != clusterv1alpha1.Push { - noPushModeCluster = append(noPushModeCluster, g.Clusters[idx]) - wg.Done() - continue - } - g.setClusterProxyInfo(karmadaRestConfig, g.Clusters[idx], clusterInfos) f := getFactory(g.Clusters[idx], clusterInfos) go g.getObjInfo(&wg, &mux, f, g.Clusters[idx], &objs, &allErrs, args) } wg.Wait() - if len(noPushModeCluster) != 0 { - fmt.Println(fmt.Sprintf(noPushModeMessage, strings.Join(noPushModeCluster, ","))) - } // sort objects by resource kind to classify them sort.Slice(objs, func(i, j int) bool {