Documentation
¶
Index ¶
Constants ¶
const (
// visible for testing
SecretTokenKey = "token"
)
Variables ¶
var ( MalformedSecret = eris.New("service account secret does not contain a bearer token") SecretNotReady = func(err error) error { return eris.Wrap(err, "secret for service account not ready yet") } // exponential backoff retry with an initial period of 0.1s for 7 iterations, which will mean a cumulative retry period of ~6s // visible for testing SecretLookupOpts = []retry.Option{ retry.Delay(time.Millisecond * 100), retry.Attempts(7), retry.DelayType(retry.BackOffDelay), } )
var (
NewClusterRBACBinderFactory = internal.NewClusterRBACBinderFactory
)
Expose internal providers for Dependency Injection
Functions ¶
func RegisterClusterFromConfig ¶
func RegisterClusterFromConfig( ctx context.Context, remoteCfg clientcmd.ClientConfig, opts RbacOptions, registrant ClusterRegistrant, ) error
Types ¶
type ClusterRegistrant ¶
type ClusterRegistrant interface {
/*
EnsureRemoteServiceAccount takes an instance of a remote config, and ensure a ServiceAccount exists on the
remote cluster, in the namespace specified.
This `ServiceAccount` can then be used and/or referenced by `CreateRemoteAccessToken` below for the remainder
of the registration workflow
*/
EnsureRemoteServiceAccount(
ctx context.Context,
remoteClientCfg clientcmd.ClientConfig,
opts Options,
) (*corev1.ServiceAccount, error)
/*
CreateRemoteAccessToken takes an instance of a remote config, and a reference to an existing `ServiceAccount`,
and attempts to bind the given `RBAC` objects to said `ServiceAccount`, in the specified cluster.
The function will then return the `ServiceAccount` token,
*/
CreateRemoteAccessToken(
ctx context.Context,
remoteClientCfg clientcmd.ClientConfig,
sa client.ObjectKey,
opts RbacOptions,
) (token string, err error)
/*
RegisterClusterWithToken takes an instance of the remote config, as well as a `BearerToken` and creates a
kubeconfig secret on the local cluster, in the specified namespace.
*/
RegisterClusterWithToken(
ctx context.Context,
remoteClientCfg clientcmd.ClientConfig,
token string,
opts Options,
) error
}
Standard Cluster Registrant (one who registers) interface.
This component is responsible for registering a "remote" kubernetes cluster to a "management" cluster. As the "management" cluster is not present in the interface itself, it is defined by the config used to build the registrant instance.
func DefaultRegistrant ¶
func DefaultRegistrant(context, clusterDomainOverride string) (ClusterRegistrant, error)
DefaultRegistrant provider function. This function will create a `ClusterRegistrant` using the current kubeconfig, and the specified context. It will build all of the dependencies from the available `ClientConfig`.
The clusterDomainOverride parameter is optional. When passed in, it will overwrite the Api Server endpoint in the kubeconfig before it is written. This is primarily useful when running multi cluster KinD environments on a mac as the local IP needs to be re-written to `host.docker.internal` so that the local instance knows to hit localhost.
Meant to be used in tandem with RegisterClusterFromConfig above. They are exposed separately so the `Registrant` may be mocked for the function above.
func NewClusterRegistrant ¶
func NewClusterRegistrant( localClusterDomainOverride string, clusterRBAC internal.ClusterRBACBinderFactory, secretClient k8s_core_v1.SecretClient, secretClientFactory k8s_core_v1_providers.SecretClientFromConfigFactory, nsClientFactory k8s_core_v1_providers.NamespaceClientFromConfigFactory, saClientFactory k8s_core_v1_providers.ServiceAccountClientFromConfigFactory, clusterRoleClientFactory rbac_v1_providers.ClusterRoleClientFromConfigFactory, roleClientFactory rbac_v1_providers.RoleClientFromConfigFactory, ) ClusterRegistrant
NewClusterRegistrant returns an implementation of ClusterRegistrant.
localClusterDomainOverride is optional. When passed in, it will overwrite the Api Server endpoint in the kubeconfig before it is written. This is primarily useful when running multi cluster KinD environments on a mac as the local IP needs to be re-written to `host.docker.internal` so that the local instance knows to hit localhost.
type Options ¶
type Options struct {
// Name by which the cluster will be identified
// If left empty will return error
ClusterName string
// Name of the remote cluster Kubeconfig Context
RemoteCtx string
// Namespace to write namespaced resources to in the "master" and "remote" clusters
// If left empty will return error
Namespace string
// Namespace to write namespaced resources to in the "master" and "remote" clusters
// If left empty will return error
RemoteNamespace string
}
type RbacOptions ¶
type RbacOptions struct {
Options
// A list of roles to bind the New kubeconfig token to
// Any Roles in this list will be Upserted by the registrant, prior to binding
Roles []*k8s_rbac_types.Role
// A list of cluster roles to bind the New kubeconfig token to
// Any ClusterRoles in this list will be Upserted by the registrant, prior to binding
ClusterRoles []*k8s_rbac_types.ClusterRole
// List of roles which will be bound to by the created role bindings
// The Roles upserted from the above list will automatically appended
RoleBindings []client.ObjectKey
// List of cluster roles which will be bound to by the created cluster role bindings
// The ClusterRoles upserted from the above list will automatically appended to the list
ClusterRoleBindings []client.ObjectKey
}
type RegistrationOptions ¶
type RegistrationOptions struct {
// override the url of the k8s server
MasterURL string
// override the path of the local kubeconfig
KubeCfgPath string
// override the context to use from the local kubeconfig.
// if unset, use current context
KubeContext string
// override the path of the remote kubeconfig
RemoteKubeCfgPath string
// override the context to use from the remote kubeconfig
// if unset, use current context
RemoteKubeContext string
// localClusterDomainOverride is optional. When passed in, it will overwrite the Api Server endpoint in
// the kubeconfig before it is written. This is primarily useful when running multi cluster KinD environments
// on a mac as the local IP needs to be re-written to `host.docker.internal` so that the local instance
// knows to hit localhost.
ClusterDomainOverride string
// Name by which the cluster will be identified
// If left empty will return error
ClusterName string
// Namespace to write namespaced resources to in the "master" and "remote" clusters
// If left empty will return error
Namespace string
// Namespace to write namespaced resources to in the "master" and "remote" clusters
// If left empty will return error
RemoteNamespace string
// A list of roles to bind the New kubeconfig token to
// Any Roles in this list will be Upserted by the registrant, prior to binding
Roles []*k8s_rbac_types.Role
// A list of cluster roles to bind the New kubeconfig token to
// Any ClusterRoles in this list will be Upserted by the registrant, prior to binding
ClusterRoles []*k8s_rbac_types.ClusterRole
// List of roles which will be bound to by the created role bindings
// The Roles upserted from the above list will automatically appended
RoleBindings []client.ObjectKey
// List of cluster roles which will be bound to by the created cluster role bindings
// The ClusterRoles upserted from the above list will automatically appended to the list
ClusterRoleBindings []client.ObjectKey
}
Options for registering a cluster
func (RegistrationOptions) RegisterCluster ¶
func (opts RegistrationOptions) RegisterCluster( ctx context.Context, ) error
RegisterCluster is meant to be a helper function to easily "register" a remote cluster. Currently this entails:
- Creating a `ServiceAccount` on the remote cluster.
- Binding RBAC `Roles/ClusterRoles` to said `ServiceAccount`
- And finally creating a kubeconfig `Secret` with the BearerToken of the remote `ServiceAccount`
Directories
¶
| Path | Synopsis |
|---|---|
|
mocks
Package mock_internal is a generated GoMock package.
|
Package mock_internal is a generated GoMock package. |
|
Package mock_clientcmd is a generated GoMock package.
|
Package mock_clientcmd is a generated GoMock package. |
|
Package mock_register is a generated GoMock package.
|
Package mock_register is a generated GoMock package. |