Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local up: use karmadactl register to register pull mode cluster #5763

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion hack/local-up-karmada.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ ${KARMADACTL_BIN} join --karmada-context="${KARMADA_APISERVER_CLUSTER_NAME}" ${M
"${REPO_ROOT}"/hack/deploy-scheduler-estimator.sh "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "${MEMBER_CLUSTER_KUBECONFIG}" "${MEMBER_CLUSTER_2_NAME}"

# step4. register pull mode member clusters and install scheduler-estimator
"${REPO_ROOT}"/hack/deploy-agent-and-estimator.sh "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "${MAIN_KUBECONFIG}" "${KARMADA_APISERVER_CLUSTER_NAME}" "${MEMBER_CLUSTER_KUBECONFIG}" "${PULL_MODE_CLUSTER_NAME}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, but this seems to mean that we will lose control of /hack/ deploy-agent-and-estimater.sh, i.e. the script may become obsolete without anyone knowing because it is not used in CI.

or we have any plan to remove /hack/ deploy-agent-and-estimater.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, long time no see 😄
nice catch, I'll add this in #5916

export VERSION="latest"
export REGISTRY="docker.io/karmada"
KARMADA_REGISTER_COMMAND=$(${KARMADACTL_BIN} token create --print-register-command --kubeconfig ${MAIN_KUBECONFIG} --karmada-context ${KARMADA_APISERVER_CLUSTER_NAME})
eval ${KARMADA_REGISTER_COMMAND} --kubeconfig "${MEMBER_CLUSTER_KUBECONFIG}" --context "${PULL_MODE_CLUSTER_NAME}" --cluster-name "${PULL_MODE_CLUSTER_NAME}" --karmada-agent-image "${REGISTRY}/karmada-agent:${VERSION}" --feature-gates CustomizedClusterResourceModeling=true,MultiClusterService=true
"${REPO_ROOT}"/hack/deploy-scheduler-estimator.sh "${MAIN_KUBECONFIG}" "${HOST_CLUSTER_NAME}" "${MEMBER_CLUSTER_KUBECONFIG}" "${PULL_MODE_CLUSTER_NAME}"

# step5. deploy metrics-server in member clusters
"${REPO_ROOT}"/hack/deploy-k8s-metrics-server.sh "${MEMBER_CLUSTER_KUBECONFIG}" "${MEMBER_CLUSTER_1_NAME}"
Expand Down
17 changes: 16 additions & 1 deletion pkg/karmadactl/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
k8srand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/wait"
kubeclient "k8s.io/client-go/kubernetes"
Expand All @@ -49,6 +50,7 @@ import (
"k8s.io/kubectl/pkg/util/templates"

"github.com/karmada-io/karmada/pkg/apis/cluster/validation"
"github.com/karmada-io/karmada/pkg/features"
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
"github.com/karmada-io/karmada/pkg/karmadactl/options"
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
Expand Down Expand Up @@ -196,7 +198,7 @@ func NewCmdRegister(parentCommand string) *cobra.Command {
flags.Int32Var(&opts.CertExpirationSeconds, "cert-expiration-seconds", DefaultCertExpirationSeconds, "The expiration time of certificate.")
flags.BoolVar(&opts.DryRun, "dry-run", false, "Run the command in dry-run mode, without making any server requests.")
flags.StringVar(&opts.ProxyServerAddress, "proxy-server-address", "", "Address of the proxy server that is used to proxy to the cluster.")

flags.StringVar(&opts.FeatureGates, "feature-gates", "", "Comma-separated list of key=value pairs that describe feature gates for alpha/experimental features of karmada-agent. More info: https://github.com/karmada-io/karmada/blob/master/pkg/features/features.go")
return cmd
}

Expand Down Expand Up @@ -259,6 +261,9 @@ type CommandRegisterOption struct {
memberClusterEndpoint string
memberClusterClient *kubeclient.Clientset

// FeatureGates for alpha/experimental features of karmada-agent.
FeatureGates string

// rbacResources contains RBAC resources that grant the necessary permissions for pull mode cluster to access to Karmada control plane.
rbacResources *RBACResources
}
Expand Down Expand Up @@ -315,6 +320,15 @@ func (o *CommandRegisterOption) Validate() error {
return fmt.Errorf("need to verify CACertHashes, or set --discovery-token-unsafe-skip-ca-verification=true")
}

if len(o.FeatureGates) != 0 {
if err := features.FeatureGate.Set(o.FeatureGates); err != nil {
return fmt.Errorf("parse flag --feature-gates failed, %s", err.Error())
}
if errs := features.FeatureGate.Validate(); len(errs) != 0 {
return fmt.Errorf("invalid feature gates(%s): %s", o.FeatureGates, utilerrors.NewAggregate(errs).Error())
}
}

return nil
}

Expand Down Expand Up @@ -1030,6 +1044,7 @@ func (o *CommandRegisterOption) makeKarmadaAgentDeployment() *appsv1.Deployment
fmt.Sprintf("--proxy-server-address=%s", o.ProxyServerAddress),
fmt.Sprintf("--leader-elect-resource-namespace=%s", o.Namespace),
fmt.Sprintf("--cluster-namespace=%s", o.ClusterNamespace),
fmt.Sprintf("--feature-gates=%s", o.FeatureGates),
"--cluster-status-update-frequency=10s",
"--metrics-bind-address=:8080",
"--health-probe-bind-address=0.0.0.0:10357",
Expand Down