Skip to content

Commit

Permalink
Enable automatic managed clusters approval
Browse files Browse the repository at this point in the history
To avoid idempotency issues in `clusteradm accept`[1] enable the
ManagedClusterAutoApproval feature gate, so `clusteradm accept` is not
needed.

Another way to solve this is to add `--skip-approve-check` option in
`clusteradm accept` but the approval step is not needed in context of a
testing environment.

[1] open-cluster-management-io/clusteradm#395

Thanks: Mike Ng <ming@redhat.com>
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs authored and raghavendra-talur committed Dec 8, 2023
1 parent ca7af2d commit f2c5575
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
6 changes: 0 additions & 6 deletions test/addons/ocm-cluster/start
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ HUB_DEPLOYMENTS = (
def deploy(cluster, hub):
wait_for_hub(hub)
join_cluster(cluster, hub)
accept_cluster(cluster, hub)
label_cluster(cluster, hub)
wait_for_managed_cluster(cluster, hub)
enable_addons(cluster, hub)
Expand Down Expand Up @@ -96,11 +95,6 @@ def join_cluster(cluster, hub):
)


def accept_cluster(cluster, hub):
print("Accepting cluster")
clusteradm.accept([cluster], wait=True, context=hub)


def label_cluster(cluster, hub):
# Managed cluster must have name=cluster label in addition to
# metadata.name.
Expand Down
7 changes: 6 additions & 1 deletion test/addons/ocm-hub/start
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ DEPLOYMENTS = {

def deploy(cluster):
print("Initializing hub")
clusteradm.init(wait=True, context=cluster)
clusteradm.init(
# With auto approval joined clusters are accepted automatically.
feature_gates=["ManagedClusterAutoApproval=true"],
wait=True,
context=cluster,
)

print("Installing hub addons")
for addon in ADDONS:
Expand Down
16 changes: 3 additions & 13 deletions test/drenv/clusteradm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from . import commands


def init(wait=False, context=None, log=print):
def init(feature_gates=None, wait=False, context=None, log=print):
"""
Initialize a Kubernetes cluster into an OCM hub cluster.
"""
cmd = ["clusteradm", "init"]
if feature_gates:
cmd.extend(("--feature-gates", ",".join(feature_gates)))
if wait:
cmd.append("--wait")
if context:
Expand Down Expand Up @@ -61,18 +63,6 @@ def join(hub_token, hub_apiserver, cluster_name, wait=False, context=None, log=p
_watch(*cmd, log=log)


def accept(clusters, wait=False, context=None, log=print):
"""
Accept clusters to the hub.
"""
cmd = ["clusteradm", "accept", "--clusters", ",".join(clusters)]
if wait:
cmd.append("--wait")
if context:
cmd.extend(("--context", context))
_watch(*cmd, log=log)


def addon(action, names, clusters, context=None, log=print):
"""
Enable or disable addons on clusters.
Expand Down

0 comments on commit f2c5575

Please sign in to comment.