本文整理汇总了Python中kubernetes.client.V1Secret方法的典型用法代码示例。如果您正苦于以下问题:Python client.V1Secret方法的具体用法?Python client.V1Secret怎么用?Python client.V1Secret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kubernetes.client
的用法示例。
在下文中一共展示了client.V1Secret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def create_secret(
kube_client: KubeClient,
secret: str,
service: str,
secret_provider: BaseSecretProvider,
) -> None:
service = sanitise_kubernetes_name(service)
sanitised_secret = sanitise_kubernetes_name(secret)
kube_client.core.create_namespaced_secret(
namespace="paasta",
body=V1Secret(
metadata=V1ObjectMeta(
name=f"paasta-secret-{service}-{sanitised_secret}",
labels={
"yelp.com/paasta_service": service,
"paasta.yelp.com/service": service,
},
),
data={
secret: base64.b64encode(
secret_provider.decrypt_secret_raw(secret)
).decode("utf-8")
},
),
)
示例2: install_github_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def install_github_secret(api_client, namespace, secret_name, github_token):
"""Install Github secret on the cluster.
Return:
secret: Secret for Github token
"""
logging.info("Install Github secret.")
corev1_api = k8s_client.CoreV1Api(api_client)
try:
secret = k8s_client.V1Secret()
secret.metadata = k8s_client.V1ObjectMeta(name=secret_name)
secret.type = "Opaque"
secret.data = {"GITHUB_TOKEN": github_token}
corev1_api.create_namespaced_secret(namespace, secret)
except rest.ApiException as e:
# Status appears to be a string.
if e.status == 409:
logging.info("Github token has already been installed")
else:
raise
示例3: install_aws_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def install_aws_secret(api_client, namespace, secret_name, aws_access_key_id, aws_secret_access_key):
"""Install AWS secret on the cluster.
Return:
secret: Secret for AWS credentials
"""
logging.info("Install AWS secret %s", secret_name)
corev1_api = k8s_client.CoreV1Api(api_client)
try:
secret = k8s_client.V1Secret()
secret.metadata = k8s_client.V1ObjectMeta(name=secret_name)
secret.type = "Opaque"
secret.data = {
"AWS_ACCESS_KEY_ID": aws_access_key_id,
"AWS_SECRET_ACCESS_KEY": aws_secret_access_key
}
corev1_api.create_namespaced_secret(namespace, secret)
except rest.ApiException as e:
# Status appears to be a string.
if e.status == 409:
logging.info("Github token has already been installed")
else:
raise
示例4: secret_create
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def secret_create(secret_data, name, namespace="default"):
"""Create a K8S Secret.
Args:
secret_data (dict): Data to store in t as key/value hash.
name (str): Name of the Secret.
namespace (str): Name of namespace.
"""
# Encode the data in a copy of the input dictionary
# TODO: We should check that Secret exists before we create it
secret_data = secret_data.copy()
for key, value in secret_data.items():
if isinstance(value, str):
value = value.encode("ascii")
secret_data[key] = base64.b64encode(value).decode("utf-8")
secret = client.V1Secret()
secret.metadata = client.V1ObjectMeta(name=name)
secret.type = "Opaque"
secret.data = secret_data
api.create_namespaced_secret(namespace=namespace, body=secret)
logging.info(f"Created Secret {name} in namespace {namespace}")
示例5: createSecret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def createSecret(cls, secret_name: str, namespace: str, secret_data: Dict[str, str],
labels: Optional[Dict[str, str]] = None) -> client.V1Secret:
"""
Creates a secret object.
:param secret_name: The name of the secret.
:param namespace: The name space for the secret.
:param secret_data: The secret data.
:param labels: Optional labels for this secret, defaults to the default labels (see `cls.createDefaultLabels`).
:return: The secret model object.
"""
return client.V1Secret(
metadata=client.V1ObjectMeta(
name=secret_name,
namespace=namespace,
labels=cls.createDefaultLabels(secret_name) if labels is None else labels
),
string_data=secret_data,
)
示例6: update_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def update_secret(
kube_client: KubeClient,
secret: str,
service: str,
secret_provider: BaseSecretProvider,
) -> None:
service = sanitise_kubernetes_name(service)
sanitised_secret = sanitise_kubernetes_name(secret)
kube_client.core.replace_namespaced_secret(
name=f"paasta-secret-{service}-{sanitised_secret}",
namespace="paasta",
body=V1Secret(
metadata=V1ObjectMeta(
name=f"paasta-secret-{service}-{sanitised_secret}",
labels={
"yelp.com/paasta_service": service,
"paasta.yelp.com/service": service,
},
),
data={
secret: base64.b64encode(
secret_provider.decrypt_secret_raw(secret)
).decode("utf-8")
},
),
)
示例7: create_secret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def create_secret(name, cert, id_token):
cert_secret_metadata = k8s_client.V1ObjectMeta(name=CERT_SECRET_NAME)
cert_secret_data = {"ca.crt": cert}
cert_secret = k8s_client.V1Secret(api_version="v1", data=cert_secret_data,
kind="Secret", metadata=cert_secret_metadata,
type="Opaque")
api_instance = get_k8s_api_client(id_token)
try:
response = api_instance.create_namespaced_secret(namespace=name,
body=cert_secret)
except ApiException as apiException:
raise KubernetesCreateException('secret', apiException)
logger.info('Secret {} created'.format(CERT_SECRET_NAME))
return response
示例8: listResources
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def listResources(self) -> List[V1Secret]:
return self.kubernetes_service.listAllSecretsWithLabels().items
示例9: getResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def getResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Secret:
name = self.getSecretName(cluster_object.metadata.name)
return self.kubernetes_service.getSecret(name, cluster_object.metadata.namespace)
示例10: createResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def createResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Secret:
name = self.getSecretName(cluster_object.metadata.name)
return self.kubernetes_service.createSecret(name, cluster_object.metadata.namespace, self._generateSecretData())
示例11: updateResource
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def updateResource(self, cluster_object: V1MongoClusterConfiguration) -> V1Secret:
name = self.getSecretName(cluster_object.metadata.name)
return self.kubernetes_service.updateSecret(name, cluster_object.metadata.namespace, self._generateSecretData())
示例12: getSecret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def getSecret(self, secret_name: str, namespace: str) -> client.V1Secret:
"""
Retrieves the secret with the given name.
:param secret_name: The name of the secret.
:param namespace: The namespace of the secret.
:return: The secret object.
"""
return self.core_api.read_namespaced_secret(secret_name, namespace)
示例13: createSecret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def createSecret(self, secret_name: str, namespace: str, secret_data: Dict[str, str],
labels: Optional[Dict[str, str]] = None) -> Optional[client.V1Secret]:
"""
Creates a new Kubernetes secret.
:param secret_name: Unique name of the secret.
:param namespace: Namespace to add secret to.
:param secret_data: The data to store in the secret as key/value pair dict.
:param labels: Optional labels for this secret, defaults to the default labels (see `cls.createDefaultLabels`).
:return: The secret if successful, None otherwise.
"""
secret_body = KubernetesResources.createSecret(secret_name, namespace, secret_data, labels)
logging.info("Creating secret %s in namespace %s", secret_name, namespace)
with IgnoreIfExists():
return self.core_api.create_namespaced_secret(namespace, secret_body)
示例14: updateSecret
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def updateSecret(self, secret_name: str, namespace: str, secret_data: Dict[str, str]) -> client.V1Secret:
"""
Updates the given Kubernetes secret.
:param secret_name: Unique name of the secret.
:param namespace: Namespace to add secret to.
:param secret_data: The data to store in the secret as key/value pair dict.
:return: The secret if successful, None otherwise.
"""
secret = self.getSecret(secret_name, namespace)
secret.string_data = secret_data
logging.info("Updating secret %s @ ns/%s", secret_name, namespace)
return self.core_api.patch_namespaced_secret(secret_name, namespace, secret)
示例15: setUp
# 需要导入模块: from kubernetes import client [as 别名]
# 或者: from kubernetes.client import V1Secret [as 别名]
def setUp(self):
self.cluster_dict = getExampleClusterDefinitionWithRestore()
self.cluster_object = V1MongoClusterConfiguration(**self.cluster_dict)
self.kubernetes_service = MagicMock()
self.restore_helper = RestoreHelper(self.kubernetes_service)
self.dummy_credentials = b64encode(json.dumps({"user": "password"}).encode())
self.kubernetes_service.getSecret.return_value = V1Secret(data={"json": self.dummy_credentials})
self.expected_cluster_members = [
"mongo-cluster-0.mongo-cluster.mongo-operator-cluster.svc.cluster.local",
"mongo-cluster-1.mongo-cluster.mongo-operator-cluster.svc.cluster.local",
"mongo-cluster-2.mongo-cluster.mongo-operator-cluster.svc.cluster.local"
]