Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator/controller: Remove PVC from the operator. #497

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions config/operator/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ rules:
- get
- list
- watch
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
44 changes: 0 additions & 44 deletions pkg/operator/controller/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ package controller
import (
"context"
"fmt"
"path/filepath"
"reflect"
"time"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -67,7 +65,6 @@ type InstanceReconciler struct {
// +kubebuilder:rbac:groups=clusterlink.net,resources=instances,verbs=list;get;watch;update;patch
// +kubebuilder:rbac:groups=clusterlink.net,resources=instances/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=clusterlink.net,resources=instances/finalizers,verbs=update
// +kubebuilder:rbac:groups="",resources=persistentvolumeclaims,verbs=list;get;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=services;serviceaccounts,verbs=list;get;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=nodes,verbs=list;get;watch
// +kubebuilder:rbac:groups="",resources=pods,verbs=list;get;watch
Expand Down Expand Up @@ -190,10 +187,6 @@ func (r *InstanceReconciler) applyClusterLink(ctx context.Context, instance *clu
instance.Spec.ContainerRegistry += "/"
}
// Create controlplane components
if err := r.createPVC(ctx, ControlPlaneName, instance.Spec.Namespace); err != nil {
return err
}

if err := r.createAccessControl(ctx, ControlPlaneName, instance.Spec.Namespace); err != nil {
return err
}
Expand Down Expand Up @@ -241,14 +234,6 @@ func (r *InstanceReconciler) applyControlplane(ctx context.Context, instance *cl
},
},
},
{
Name: ControlPlaneName,
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: ControlPlaneName,
},
},
},
},
Containers: []corev1.Container{
{
Expand Down Expand Up @@ -280,10 +265,6 @@ func (r *InstanceReconciler) applyControlplane(ctx context.Context, instance *cl
SubPath: "key",
ReadOnly: true,
},
{
Name: ControlPlaneName,
MountPath: filepath.Dir(cpapp.StoreFile),
},
},
Env: []corev1.EnvVar{
{
Expand Down Expand Up @@ -408,27 +389,6 @@ func (r *InstanceReconciler) createService(ctx context.Context, name, namespace
return r.createResource(ctx, service)
}

// createPVC sets up k8s a persistent volume claim for the.
func (r *InstanceReconciler) createPVC(ctx context.Context, name, namespace string) error {
// Create the PVC for cl-controlplane
controlplanePVC := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: corev1.PersistentVolumeClaimSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
Resources: corev1.VolumeResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceStorage: resource.MustParse("100Mi"),
},
},
},
}

return r.createResource(ctx, controlplanePVC)
}

// createAccessControl sets up k8s ClusterRule and ClusterRoleBinding for the controlplane.
func (r *InstanceReconciler) createAccessControl(ctx context.Context, name, namespace string) error {
// Create ServiceAccount object
Expand Down Expand Up @@ -607,10 +567,6 @@ func (r *InstanceReconciler) deleteClusterLink(ctx context.Context, namespace st
return err
}

if err := r.deleteResource(ctx, &corev1.PersistentVolumeClaim{ObjectMeta: cpObj}); err != nil {
return err
}

if err := r.deleteResource(ctx, &rbacv1.ClusterRole{ObjectMeta: cpObj}); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/controller/instance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestClusterLinkController(t *testing.T) {
}

cpID := types.NamespacedName{Name: controller.ControlPlaneName, Namespace: controller.InstanceNamespace}
cpResource := []client.Object{&appsv1.Deployment{}, &corev1.Service{}, &corev1.PersistentVolumeClaim{}}
cpResource := []client.Object{&appsv1.Deployment{}, &corev1.Service{}}
roleID := types.NamespacedName{
Name: controller.ControlPlaneName + controller.InstanceNamespace,
Namespace: controller.InstanceNamespace,
Expand Down
Loading