Class KubernetesCredentialFactory
- All Implemented Interfaces:
ISecretProvider
CredentialFactory for Kubernetes Secret. Fetches credentials from Kubernetes secrets.
The credentials are stored in Kubernetes secrets, which are base64 encoded. The keys used for the secrets are "username" and "password".
The `KubernetesCredentialFactory` class uses several properties to configure its behavior. These properties are set in the
credentialproperties.properties file and are used to customize the connection to the Kubernetes cluster and the namespace from which secrets are
fetched. Here's a description of the properties:
credentialFactory.kubernetes.username- the username for authenticating with the Kubernetes clustercredentialFactory.kubernetes.password- the password for authenticating with the Kubernetes clustercredentialFactory.kubernetes.masterUrl- the master URL of the Kubernetes clustercredentialFactory.kubernetes.namespace- the namespace from which secrets should be fetched (default value: 'current-namespace')
Example configuration:
credentialFactory.kubernetes.username=admin
credentialFactory.kubernetes.password=example-password
credentialFactory.kubernetes.masterUrl=http://localhost:8080
credentialFactory.kubernetes.namespace=my-namespace
By setting these properties, you can control how the `KubernetesCredentialFactory` interacts with the Kubernetes cluster and retrieves credentials.
Adding a Kubernetes secret can be done by executing:
kubectl create secret generic db-alias-name \
--from-literal=username=admin --from-literal=password='example-password'
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close Kubernetes clientreturn a list of all configured aliases, or null if such a list cannot be provided.getSecret(CredentialAlias alias) protected List<io.fabric8.kubernetes.api.model.Secret> booleanhasSecret(CredentialAlias alias) voidinitialize() of an implementation can throw an exception when the credentialFactory cannot be properly configured and used.
-
Field Details
-
DEFAULT_NAMESPACE
- See Also:
-
namespace
-
-
Constructor Details
-
KubernetesCredentialFactory
public KubernetesCredentialFactory()
-
-
Method Details
-
initialize
public void initialize()Description copied from interface:ISecretProviderinitialize() of an implementation can throw an exception when the credentialFactory cannot be properly configured and used.- Specified by:
initializein interfaceISecretProvider
-
hasSecret
- Specified by:
hasSecretin interfaceISecretProvider
-
getSecret
- Specified by:
getSecretin interfaceISecretProvider- Throws:
NoSuchElementException
-
getConfiguredAliases
Description copied from interface:ISecretProviderreturn a list of all configured aliases, or null if such a list cannot be provided.- Specified by:
getConfiguredAliasesin interfaceISecretProvider
-
getSecretsFromKubernetes
-
close
public void close()Close Kubernetes client
-