Skip to content

Commit

Permalink
feat(shared): dynamically generate storage class through a single tem…
Browse files Browse the repository at this point in the history
…plate file for various cloud providers

This commit introduces a solution to simplify the process of generating storage classes for various cloud providers in the bevel project.

Changes:
 • Created Helm chart "storage_class" with a single template file for dynamic generation of storage classes based on various cloud providers.
 • Implemented Helm Release (HR) template file to configure the storage_class chart.

Additional changes:
 • Fixed code to generate the StorageClass HR file inside the organization directory, ensuring proper deletion during network reset.
 • Fixed deletion code to effectively remove deployed StorageClasses from the Kubernetes cluster.

Benefits:
 • Simplifies switching between cloud providers by updating the "cloud_provider" field in the network configuration file.
 • Streamlines the generation and management of storage classes in the bevel project.
 • Reduces code duplication and maintenance overhead by utilizing a single template file for all cloud providers.

fixes #2306

Signed-off-by: saurabhkumarkardam <[email protected]>
  • Loading branch information
saurabhkumarkardam authored and suvajit-sarkar committed Jul 5, 2023
1 parent 32e3176 commit a9210f7
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 48 deletions.
6 changes: 5 additions & 1 deletion platforms/hyperledger-besu/configuration/deploy-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@
git_dir: "{{ organizationItem.gitops.release_dir }}"
org: "{{ organizationItem }}"
kubernetes: "{{ organizationItem.k8s }}"
cloudProvider: "{{ organizationItem.cloud_provider }}"
cloudProvider_info: "{{ organizationItem[cloudProvider] }}"
charts_dir: "platforms/shared/charts"
org_name: "{{ organizationItem.name | lower }}"
loop: "{{ network['organizations'] }}"
loop_control:
loop_var: organizationItem

#Create Vault scrit as configmap for Vault CURD operations
- name: setup vault script
include_role:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: {{ component_name }}
namespace: {{ org_name }}-bes
annotations:
flux.weave.works/automated: "false"
spec:
releaseName: {{ component_name }}
interval: 1m
chart:
spec:
chart: {{ charts_dir }}/storage_class
sourceRef:
kind: GitRepository
name: flux-{{ network.env.type }}
namespace: flux-{{ network.env.type }}
values:
metadata:
name: {{ component_name }}
cloud_provider: {{ cloudProvider }}
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowedTopologies:
- matchLabelExpressions:
- key: failure-domain.beta.kubernetes.io/zone
values:
- "{{ cloudProvider_info.region }}a"
- "{{ cloudProvider_info.region }}b"
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

dlt_templates:
namespace: namespace.tpl
aws-storageclass: eks_csi_storageclass.tpl # use eks_storageclass.tpl for non csi provisioning on eks 1.22 or below
minikube-storageclass: mini_storageclass.tpl
gcp-storageclass: gcp-storageclass.tpl
aws-storageclass: storageclass.tpl
minikube-storageclass: storageclass.tpl
gcp-storageclass: storageclass.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
component_type: "{{ org.cloud_provider}}-storageclass"
component_name: "{{ storageclass_name }}"
helm_lint: "false"
release_dir: "{{ playbook_dir }}/../../../{{ org.gitops.release_dir }}"
release_dir: "{{ playbook_dir }}/../../../{{ org.gitops.release_dir }}/{{ org_name }}"
when: storageclass_state.resources|length == 0

# Push the deployment files to repository
Expand Down
11 changes: 11 additions & 0 deletions platforms/shared/charts/storage_class/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##############################################################################################
# Copyright Accenture. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
##############################################################################################

apiVersion: v1
appVersion: "2.0"
description: "Shared: Deploys a StorageClass that can be used to provision persistent volumes for nodes."
name: shared_StorageClass_chart
version: '0.14.1'
174 changes: 174 additions & 0 deletions platforms/shared/charts/storage_class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
[//]: # (##############################################################################################)
[//]: # (Copyright Accenture. All Rights Reserved.)
[//]: # (SPDX-License-Identifier: Apache-2.0)
[//]: # (##############################################################################################)

<a name = "deploy-storageclass"></a>
# Deploy StorageClass

- [StorageClass Helm Chart](#storageclass-helm-chart)
- [Prerequisites](#prerequisites)
- [Chart Structure](#chart-structure)
- [Configuration](#configuration)
- [Deployment](#deployment)
- [Verification](#verification)
- [Updating the Deployment](#updating-the-deployment)
- [Deletion](#deletion)
- [Contributing](#contributing)
- [License](#license)


<a name = "storageclass-helm-chart"></a>
## StorageClass Helm Chart
---
This [Helm chart](https://github.com/hyperledger/bevel/tree/main/platforms/shared/charts/storage_class) deploys a StorageClass that can be used to provision persistent volumes for nodes. The StorageClass supports encryption and can be configured to be used in specific topologies.


<a name = "prerequisites"></a>
## Prerequisites
---
Before deploying the Helm chart, make sure to have the following prerequisites:

- Kubernetes cluster up and running.
- Helm installed.
- An AWS account with EBS enabled.


<a name = "chart-structure"></a>
## Chart Structure
---
The structure of the Helm chart is as follows:

```
storage_class/
|- templates/
|- _heplers.tpl
|- storageclass.yaml
|- Chart.yaml
|- README.md
|- values.yaml
```

- `_heplers.tpl`: It is a resuable template file to support the Helm chart. The provisioner function in this file can be used to get the appropriate provisioner name for a given cloud provider.
- `templates/`: This directory contains the Kubernetes manifest templates that define the resources to be deployed.
- `storageclass.yaml`:This file defines the StorageClass that is deployed by the chart. It specifies the name of the StorageClass, the storage provisioner to use, the reclaim policy, the volume binding mode, and any other parameters that are needed to configure the StorageClass.
- `Chart.yaml`: This file contains metadata about the chart, such as its name, version, description, and dependencies.
- `README.md`: This file provides information and instructions about the Helm chart.
- `values.yaml`: This file contains the default configuration values for the Helm chart.


<a name = "configuration"></a>
## Configuration
---
The [values.yaml](https://github.com/hyperledger/bevel/tree/main/platforms/shared/charts/storage_class/values.yaml) file contains configurable values for the Helm chart. We can modify these values according to the deployment requirements. Here are some important configuration options:

## Parameters
---

### metadata

| Name | Description | Default Value |
| --------| --------------------------------| -------------------|
| name | The name of the StorageClass. | bevel-storageclass |

### cloud_provider

| Name | Description | Default Value |
| ------------------| ------------------------------------------------------------------------------ | ------------- |
| cloud_provider | The name of the cloud provider. Supported values are: aws, gcp, or minikube. | aws |

### provisioner

| Name | Description | Default Value |
| -------------| -------------------------------------------------------------------------------------------------------------------| ------------- |
| provisioner | Optional field. Fill it only if you want to use a specific provisioner of your choice.<br>Otherwise, leave it empty to use the default provisioner based on the value of "cloud_provider" field. | "" |

### reclaimPolicy

| Name | Description | Default Value |
| ----------------| -------------------------------------------------------------------------------------------------------------- | ------------- |
| reclaimPolicy | The reclaim policy for persistent volumes created by the StorageClass. Supported values are: Delete or Retain. | Delete |

### volumeBindingMode

| Name | Description | Default Value |
| -----------------| ----------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| volumeBindingMode| The volume binding mode for persistent volumes created by the StorageClass. Supported values are: Immediate or WaitForFirstConsumer.| Immediate |

### parameters

| Name | Description | Default Value |
| ---------------------| -----------------------------------------------| -----------------------------------------------------------|
| parameters.aws | Parameters for AWS storage provisioner. | encrypted: "true" |
| parameters.aws | Parameters for GCP storage provisioner. | type: pd-standard<br>fstype: ext4<br>replicationtype: none |
| parameters.minikube | Parameters for Minikube storage provisioner. | encrypted: "true" |

### allowedTopologies

| Name | Description | Default Value |
| ------------------------------| --------------------------------------------------| ------------------------------------------|
| matchLabelExpressions | Label expression to specify the allowed zones. | "" |
| matchLabelExpressions.key | Key of the label used for matching. | failure-domain.beta.kubernetes.io/zone |
| matchLabelExpressions.values | List of values for the specified label key. | eu-east-1a, eu-east-1b |

a name = "deployment"></a>
## Deployment
---

To deploy the storage_class Helm chart, follow these steps:

1. Modify the [values.yaml](https://github.com/hyperledger/bevel/tree/main/platforms/shared/charts/storage_class/values.yaml) file to set the desired configuration values.
2. Run the following Helm command to install the chart:
```
$ helm repo add bevel https://hyperledger.github.io/bevel/
$ helm install <release-name> ./storage_class
```
Replace `<release-name>` with the desired name for the release.
This will deploy the StorageClass to the Kubernetes cluster based on the provided configurations.
<a name = "verification"></a>
## Verification
---
To verify the deployment, we can use the following command:
```
$ kubectl get storageclasses <storage-class-name>
```
Replace `<storage-class-name>` with the name of the StorageClass provided in the values.yaml.
This will list the StorageClass that was deployed. The output of the command will include the name of the StorageClass, the storage provisioner that is used, the reclaim policy, and the volume binding mode.
<a name = "updating-the-deployment"></a>
## Updating the Deployment
---
If we need to update the deployment with new configurations or changes, modify the same [values.yaml](https://github.com/hyperledger/bevel/tree/main/platforms/shared/charts/storage_class/values.yaml) file with the desired changes and run the following Helm command:
```
$ helm upgrade <release-name> ./storage_class
```
Replace `<release-name>` with the name of the release. This command will apply the changes to the deployment, ensuring the StorageClass is up to date.
<a name = "deletion"></a>
## Deletion
---
To delete the deployed StorageClass, run the following Helm command:
```
$ helm uninstall <release-name>
```
Replace `<release-name>` with the name of the release. This command will remove the StorageClass.
<a name = "contributing"></a>
## Contributing
---
If you encounter any bugs, have suggestions, or would like to contribute to the [StorageClass Helm Chart](https://github.com/hyperledger/bevel/tree/main/platforms/shared/charts/storage_class), please feel free to open an issue or submit a pull request on the [project's GitHub repository](https://github.com/hyperledger/bevel).
<a name = "license"></a>
## License
This chart is licensed under the Apache v2.0 license.
Copyright &copy; 2023 Accenture
### Attribution
This chart is adapted from the [charts](https://hyperledger.github.io/bevel/) which is licensed under the Apache v2.0 License which is reproduced here:
```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
9 changes: 9 additions & 0 deletions platforms/shared/charts/storage_class/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- define "provisioner" -}}
{{- if eq .Values.cloud_provider "aws" }}
provisioner: ebs.csi.aws.com
{{- else if eq .Values.cloud_provider "gcp" }}
provisioner: gce.csi.google.com
{{- else if eq .Values.cloud_provider "minikube" }}
provisioner: k8s.io/minikube-hostpath
{{- end -}}
{{- end -}}
36 changes: 36 additions & 0 deletions platforms/shared/charts/storage_class/templates/storageclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
##############################################################################################
# Copyright Accenture. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
##############################################################################################

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: "{{ .Values.metadata.name }}"
reclaimPolicy: "{{ .Values.reclaimPolicy }}"
volumeBindingMode: "{{ .Values.volumeBindingMode }}"
{{- if .Values.provisioner }}
provisioner: "{{ .Values.provisioner }}"
{{- else }}
{{ include "provisioner" . }}
{{- end }}
{{- with index .Values.parameters (index .Values.cloud_provider) }}
parameters:
{{- range $key, $value := . }}
{{ $key }}: "{{ $value }}"
{{- end }}
{{- end }}
{{- if .Values.allowedTopologies }}
allowedTopologies:
{{- range .Values.allowedTopologies }}
- matchLabelExpressions:
{{- range .matchLabelExpressions }}
- key: {{ .key }}
values:
{{- range .values }}
- {{ . | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
55 changes: 55 additions & 0 deletions platforms/shared/charts/storage_class/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
##############################################################################################
# Copyright Accenture. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
##############################################################################################

metadata:
# The name of the StorageClass.
name: bevel-storageclass

# The name of the cloud provider. Supported values are: aws, gcp, or minikube.
# The `aws` value specifies that the StorageClass will be used for provisioning PersistentVolumes on AWS.
# The `gcp` value specifies that the StorageClass will be used for provisioning PersistentVolumes on GCP.
# The `minikube` value specifies that the StorageClass will be used for provisioning PersistentVolumes on Minikube.
cloud_provider: aws

# This "provisioner" is an optional field.
# Fill it only if you want to use a specific provisioner of your choice.
# Otherwise, leave it empty to use the default provisioner based on the value of "cloud_provider" field.
provisioner:

# The parameters that will be passed to the storage provisioner.
# The `aws` key specifies the parameters that will be passed to the AWS storage provisioner.
# The `gcp` key specifies the parameters that will be passed to the GCP storage provisioner.
# The `minikube` key specifies the parameters that will be passed to the Minikube storage provisioner.
parameters:
aws:
encrypted: "true"
gcp:
type: pd-standard
fstype: ext4
replicationtype: none
minikube:
encrypted: "true"

# The policy for deleting PersistentVolumes that are provisioned by this StorageClass. Supported values are: Delete or Retain.
# The `Delete` value specifies that PersistentVolumes that are provisioned by this StorageClass will be deleted when they are no longer in use.
# The `Retain` value specifies that PersistentVolumes that are provisioned by this StorageClass will not be deleted when they are no longer in use.
reclaimPolicy: Delete

# The mode for binding PersistentVolumes that are provisioned by this StorageClass. Supported values are: Immediate or WaitForFirstConsumer.
# The `Immediate` value specifies that PersistentVolumes that are provisioned by this StorageClass will be bound to Pods immediately.
# The `WaitForFirstConsumer` value specifies that PersistentVolumes that are provisioned by this StorageClass will not be bound to Pods until a Pod requests a PersistentVolume of that StorageClass.
volumeBindingMode: Immediate

# A list of allowed topologies for PersistentVolumes that are provisioned by this StorageClass.
# The `allowedTopologies` list specifies the zones in which PersistentVolumes that are provisioned by this StorageClass can be created.
allowedTopologies:
# A label expression that specifies the allowed zones.
- matchLabelExpressions:
- key: failure-domain.beta.kubernetes.io/zone
values:
# The allowed zones.
- "eu-west-1a"
- "eu-west-1b"
Loading

0 comments on commit a9210f7

Please sign in to comment.