Implement karmadactl get to support pull mode cluster

Signed-off-by: lonelyCZ <531187475@qq.com>
This commit is contained in:
lonelyCZ 2022-04-02 14:46:16 +08:00
parent 9cbe962748
commit 93c3c04c35
3 changed files with 7 additions and 12 deletions

View File

@ -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:

View File

@ -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

View File

@ -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 {