Add CreatePVC and DeletePVC to KubernetesService

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mr
2026-03-23 11:42:58 +01:00
parent 5bdd2554a7
commit 5b197c91e0

View File

@@ -14,6 +14,7 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1" rbacv1 "k8s.io/api/rbac/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors" apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
@@ -598,6 +599,38 @@ func (k *KubernetesService) CreateSecret(context context.Context, minioId string
return nil return nil
} }
// CreatePVC creates a PersistentVolumeClaim in the given namespace.
func (k *KubernetesService) CreatePVC(ctx context.Context, name, namespace, storageSize string) error {
pvc := &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Resources: v1.VolumeResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceStorage: resource.MustParse(storageSize),
},
},
},
}
_, err := k.Set.CoreV1().PersistentVolumeClaims(namespace).Create(ctx, pvc, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("CreatePVC %s/%s: %w", namespace, name, err)
}
return nil
}
// DeletePVC deletes a PersistentVolumeClaim from the given namespace.
func (k *KubernetesService) DeletePVC(ctx context.Context, name, namespace string) error {
err := k.Set.CoreV1().PersistentVolumeClaims(namespace).Delete(ctx, name, metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("DeletePVC %s/%s: %w", namespace, name, err)
}
return nil
}
// ============== ADMIRALTY ============== // ============== ADMIRALTY ==============
// Returns a concatenation of the peerId and namespace in order for // Returns a concatenation of the peerId and namespace in order for
// kubernetes ressources to have a unique name, under 63 characters // kubernetes ressources to have a unique name, under 63 characters