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

Extend KubernetesCluster status with registration settings #143

Merged
merged 15 commits into from
Sep 18, 2020
Merged
Prev Previous commit
Next Next commit
add option for not deleting remote cluster resources when deregisteri…
…ng a non-existent cluster
harveyxia committed Sep 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 944886cfb07b71d6273c73fcf4aeadb3cef862dc
3 changes: 1 addition & 2 deletions codegen/test/api/things.test.io/v1/test_api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions codegen/test/api/things.test.io/v1/test_api_json.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/api/core.skv2.solo.io/v1/core.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/api/core.skv2.solo.io/v1/core_json.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/api/multicluster.solo.io/v1alpha1/cluster.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pkg/api/multicluster.solo.io/v1alpha1/cluster_json.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions pkg/multicluster/register/helpers.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

// Options for registering a cluster
// Options for registering and deregistering a cluster
type RegistrationOptions struct {
// Management kubeconfig
KubeCfg clientcmd.ClientConfig
@@ -73,6 +73,10 @@ type RegistrationOptions struct {

// Set of labels to include on the registration output resources, currently consisting of KubernetesCluster and Secret.
ResourceLabels map[string]string

// Set to true if the remote cluster no longer exists (e.g. was deleted).
// If true, deregistration will not attempt to delete registration resources on the remote cluster.
RemoteClusterDeleted bool
}

/*
@@ -147,11 +151,12 @@ func (opts RegistrationOptions) initialize(
rolePolicyRules, clusterRolePolicyRules := collectPolicyRules(opts.Roles, opts.ClusterRoles)

registrationOpts = Options{
ClusterName: opts.ClusterName,
Namespace: opts.Namespace,
RemoteCtx: opts.RemoteCtx,
RemoteNamespace: opts.RemoteNamespace,
ClusterDomain: opts.ClusterDomain,
ClusterName: opts.ClusterName,
Namespace: opts.Namespace,
RemoteCtx: opts.RemoteCtx,
RemoteNamespace: opts.RemoteNamespace,
ClusterDomain: opts.ClusterDomain,
RemoteClusterDeleted: opts.RemoteClusterDeleted,
RbacOptions: RbacOptions{
Roles: opts.Roles,
ClusterRoles: opts.ClusterRoles,
@@ -250,6 +255,11 @@ func DeregisterClusterFromConfig(
multierr = multierror.Append(multierr, err)
}

// Do not attempt to delete remote registration resources if remote cluster no longer exists.
if opts.RemoteClusterDeleted {
return multierr.ErrorOrNil()
}

if err := registrant.DeleteRemoteServiceAccount(ctx, remoteCfg, opts); err != nil {
multierr = multierror.Append(multierr, err)
}
4 changes: 4 additions & 0 deletions pkg/multicluster/register/interfaces.go
Original file line number Diff line number Diff line change
@@ -50,6 +50,10 @@ type Options struct {
RegistrationMetadata RegistrationMetadata

RbacOptions RbacOptions

// Set to true if the remote cluster no longer exists (e.g. was deleted).
// If true, deregistration will not attempt to delete registration resources on the remote cluster.
RemoteClusterDeleted bool
}

// Optional additional metadata to persist to registration output resources.