Skip to content

Commit

Permalink
Support hostPID and autoscaling
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmxs committed Nov 7, 2022
1 parent f9bf4fc commit 3b61590
Show file tree
Hide file tree
Showing 29 changed files with 936 additions and 832 deletions.
24 changes: 5 additions & 19 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ rules:
- apiGroups:
- ""
resources:
- endpoints
- namespaces
verbs:
- list
- watch
- get
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -44,28 +43,14 @@ rules:
resources:
- persistentvolumes
verbs:
- list
- apiGroups:
- ""
resources:
- pods
verbs:
- delete
- get
- apiGroups:
- ""
resources:
- services
- pods
verbs:
- create
- delete
- update
- apiGroups:
- ""
resources:
- services/finalizers
verbs:
- update
- list
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -128,6 +113,7 @@ rules:
resources:
- storageclasses
verbs:
- create
- get
- update
- apiGroups:
Expand Down
17 changes: 8 additions & 9 deletions controllers/diskconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,24 @@ func (r *DiskConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

func (r *DiskConfigReconciler) reconcileDelete(ctx context.Context, configName, configNamespace string, logger logr.Logger) (ctrl.Result, error) {
nsFinalizer := utils.RenderFinalizer(configName, configNamespace)

logger.Info("Fetch StrorageClasses...")

scList := storagev1.StorageClassList{}
if err := r.Client.List(ctx, &scList); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to list StorageClasses: %w", err)
}

scFinalizer := utils.RenderFinalizer(configName, configNamespace)

for i := range scList.Items {
if scList.Items[i].DeletionTimestamp != nil || !controllerutil.ContainsFinalizer(&scList.Items[i], scFinalizer) {
if !controllerutil.ContainsFinalizer(&scList.Items[i], nsFinalizer) {
continue
}

controllerutil.RemoveFinalizer(&scList.Items[i], scFinalizer)
controllerutil.RemoveFinalizer(&scList.Items[i], nsFinalizer)

logger := logger.WithValues("sc_name", scList.Items[i].Name)
logger.Info("Remove StorageClass finalizer...", "finalizer", scFinalizer)
logger.Info("Remove StorageClass finalizer...", "finalizer", nsFinalizer)

if err := r.Client.Update(ctx, &scList.Items[i]); err != nil {
logger.Info("Failed to remove finalizer of StorageClass", "error", err.Error())
Expand All @@ -170,7 +170,7 @@ func (r *DiskConfigReconciler) reconcileDelete(ctx context.Context, configName,
pvcSelector := labels.NewSelector().Add(*label)

pvcList := corev1.PersistentVolumeClaimList{}
if err = r.List(ctx, &pvcList, &client.ListOptions{
if err = r.Client.List(ctx, &pvcList, &client.ListOptions{
Namespace: configNamespace,
LabelSelector: pvcSelector,
}); err != nil {
Expand All @@ -190,7 +190,7 @@ func (r *DiskConfigReconciler) reconcileDelete(ctx context.Context, configName,
go func() {
defer wg.Done()

unlock, err := utils.WaitForSemaphore(ctx, sem, errChan)
unlock, err := utils.WaitForSemaphore(ctx, sem)
if err != nil {
logger.Info("Context deadline")
errChan <- fmt.Errorf("context deadline %s->%s", pvcList.Items[i].GetNamespace(), pvcList.Items[i].GetName())
Expand All @@ -203,7 +203,7 @@ func (r *DiskConfigReconciler) reconcileDelete(ctx context.Context, configName,
logger := logger.WithValues("pvc_name", pvcList.Items[i].Name, "pvc_namespace", pvcList.Items[i].Namespace)
logger.Info("Update PVC finalizer...", "finalizer", finalizer)

if err = r.Update(ctx, &pvcList.Items[i]); err != nil {
if err = r.Client.Update(ctx, &pvcList.Items[i]); err != nil {
logger.Info("Failed to remove finalizer of PVC", "error", err.Error())
errChan <- fmt.Errorf("unable to remove finalizer of PVC %s->%s: %w", pvcList.Items[i].Namespace, pvcList.Items[i].Name, err)
return
Expand Down Expand Up @@ -249,7 +249,6 @@ func (r *DiskConfigReconciler) reconcileUpdate(ctx context.Context, config *disc
logger = logger.WithValues("sc_name", config.Spec.StorageClassName)

scFinalizer := utils.RenderFinalizer(config.Name, config.Namespace)

if !controllerutil.ContainsFinalizer(&sc, scFinalizer) {
controllerutil.AddFinalizer(&sc, scFinalizer)

Expand Down
7 changes: 6 additions & 1 deletion controllers/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ func (r *JobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R

logger.Info("Delete Job...")

return ctrl.Result{}, r.Client.Delete(ctx, &batchv1.Job{
err = r.Client.Delete(ctx, &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: req.Name,
Namespace: req.Namespace,
},
})
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
141 changes: 0 additions & 141 deletions controllers/pod_controller.go

This file was deleted.

Loading

0 comments on commit 3b61590

Please sign in to comment.