community.kubevirt.kubevirt_pvc – Manage PVCs on Kubernetes
Note
This plugin is part of the community.kubevirt collection (version 1.0.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.kubevirt
.
To use it in a playbook, specify: community.kubevirt.kubevirt_pvc
.
Synopsis
Use Openshift Python SDK to manage PVCs on Kubernetes
Support Containerized Data Importer out of the box
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.7
openshift >= 0.8.2
Parameters
Parameter |
Comments |
---|---|
Contains the desired access modes the volume should have. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes |
|
Annotations attached to this object. https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ |
|
Token used to authenticate with the API. Can also be specified via K8S_AUTH_API_KEY environment variable. |
|
Path to a CA certificate used to authenticate with the API. The full certificate chain must be provided to avoid certificate validation errors. Can also be specified via K8S_AUTH_SSL_CA_CERT environment variable. |
|
If data is to be copied onto the PVC using the Containerized Data Importer you can specify the source of the data (along with any additional configuration) as well as it’s format. Valid source types are: blank, http, s3, registry, pvc and upload. The last one requires using the community.kubevirt.kubevirt_cdi_upload module to actually perform an upload. Source data format is specified using the optional content_type. Valid options are This uses the DataVolume source syntax: https://github.com/kubevirt/containerized-data-importer/blob/master/doc/datavolumes.md#https3registry-source |
|
Path to a certificate used to authenticate with the API. Can also be specified via K8S_AUTH_CERT_FILE environment variable. |
|
Path to a key file used to authenticate with the API. Can also be specified via K8S_AUTH_KEY_FILE environment variable. |
|
The name of a context found in the config file. Can also be specified via K8S_AUTH_CONTEXT environment variable. |
|
If set to Choices:
|
|
Provide a URL for accessing the API. Can also be specified via K8S_AUTH_HOST environment variable. |
|
Path to an existing Kubernetes config file. If not provided, and no other connection options are provided, the openshift client will attempt to load the default configuration file from ~/.kube/config.json. Can also be specified via K8S_AUTH_KUBECONFIG environment variable. |
|
Labels attached to this object. https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ |
|
Whether to override the default patch merge approach with a specific type. This defaults to If more than one merge_type is given, the merge_types will be tried in order Choices:
|
|
Use to specify a PVC object name. |
|
Use to specify a PVC object namespace. |
|
Provide a password for authenticating with the API. Can also be specified via K8S_AUTH_PASSWORD environment variable. Please read the description of the |
|
Whether or not to save the kube config refresh tokens. Can also be specified via K8S_AUTH_PERSIST_CONFIG environment variable. When the k8s context is using a user credentials with refresh tokens (like oidc or gke/gcloud auth), the token is refreshed by the k8s python client library but not saved by default. So the old refresh token can expire and the next auth might fail. Setting this flag to true will tell the k8s python client to save the new refresh token to the kube config file. Default to false. Please note that the current version of the k8s python client library does not support setting this flag to True yet. The fix for this k8s python library is here: https://github.com/kubernetes-client/python-base/pull/169 Choices:
|
|
The URL of an HTTP proxy to use for the connection. Can also be specified via K8S_AUTH_PROXY environment variable. Please note that this module does not pick up typical proxy settings from the environment (e.g. HTTP_PROXY). |
|
A partial YAML definition of the PVC object being created/updated. Here you can define Kubernetes PVC Resource parameters not covered by this module’s parameters. NOTE: resource_definition has lower priority than module parameters. If you try to define e.g. metadata.namespace here, that value will be ignored and namespace used instead. |
|
A label query over volumes to consider for binding. https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ |
|
How much storage to allocate to the PVC. |
|
Determines if an object should be created, patched, or deleted. When set to Choices:
|
|
Name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1 |
|
Provide a username for authenticating with the API. Can also be specified via K8S_AUTH_USERNAME environment variable. Please note that this only works with clusters configured to use HTTP Basic Auth. If your cluster has a different form of authentication (e.g. OAuth2 in OpenShift), this option will not work as expected and you should look into the |
|
Whether or not to verify the API server’s SSL certificates. Can also be specified via K8S_AUTH_VERIFY_SSL environment variable. Choices:
|
|
This defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec. This is an alpha feature of kubernetes and may change in the future. |
|
This is the binding reference to the PersistentVolume backing this claim. |
|
If set, this module will wait for the PVC to become bound and CDI (if enabled) to finish its operation before returning. Used only if state set to Unless used in conjunction with cdi_source, this might result in a timeout, as clusters may be configured to not bind PVCs until first usage. Choices:
|
|
Specifies how much time in seconds to wait for PVC creation to complete if wait option is enabled. Default value is reasonably high due to an expectation that CDI might take a while to finish its operation. Default: 300 |
Notes
Note
The OpenShift Python client wraps the K8s Python client, providing full access to all of the APIS and models available on both platforms. For API version details and additional information visit https://github.com/openshift/openshift-restclient-python
To avoid SSL certificate validation errors when
validate_certs
is True, the full certificate chain for the API server must be provided viaca_cert
or in the kubeconfig file.
Examples
- name: Create a PVC and import data from an external source
community.kubevirt.kubevirt_pvc:
name: pvc1
namespace: default
size: 100Mi
access_modes:
- ReadWriteOnce
cdi_source:
http:
url: https://www.source.example/path/of/data/vm.img
# If the URL points to a tar.gz containing the disk image, uncomment the line below:
#content_type: archive
- name: Create a PVC as a clone from a different PVC
community.kubevirt.kubevirt_pvc:
name: pvc2
namespace: default
size: 100Mi
access_modes:
- ReadWriteOnce
cdi_source:
pvc:
namespace: source-ns
name: source-pvc
- name: Create a PVC ready for data upload
community.kubevirt.kubevirt_pvc:
name: pvc3
namespace: default
size: 100Mi
access_modes:
- ReadWriteOnce
cdi_source:
upload: yes
# You need the kubevirt_cdi_upload module to actually upload something
- name: Create a PVC with a blank raw image
community.kubevirt.kubevirt_pvc:
name: pvc4
namespace: default
size: 100Mi
access_modes:
- ReadWriteOnce
cdi_source:
blank: yes
- name: Create a PVC and fill it with data from a container
community.kubevirt.kubevirt_pvc:
name: pvc5
namespace: default
size: 100Mi
access_modes:
- ReadWriteOnce
cdi_source:
registry:
url: "docker://kubevirt/fedora-cloud-registry-disk-demo"
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The created, patched, or otherwise present object. Will be empty in the case of a deletion. Returned: success |
|
The versioned schema of this representation of an object. Returned: success |
|
elapsed time of task in seconds Returned: when Sample: 48 |
|
Returned only when multiple yaml documents are passed to src or resource_definition Returned: when resource_definition or src contains list of objects |
|
Represents the REST resource this object represents. Returned: success |
|
Standard object metadata. Includes name, namespace, annotations, labels, etc. Returned: success |
|
Specific attributes of the object. Will vary based on the api_version and kind. Returned: success |
|
Current status details for the object. Returned: success |
Authors
KubeVirt Team (@kubevirt)