-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow creating PVC, so the kube jobs can use PVCs as a cache across multiple jobs.
- Loading branch information
1 parent
6b173f6
commit fd092f7
Showing
2 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 PayPal Inc. | ||
|
||
// This Source Code Form is subject to the terms of the MIT License. | ||
// If a copy of the MIT License was not distributed with this file, | ||
// you can obtain one at https://mit-license.org/. | ||
|
||
// Package honeydipper is an event-driven, rule based orchestration platform tailor towards | ||
// DevOps and system engineering workflows. | ||
package main | ||
|
||
import ( | ||
"github.com/ghodss/yaml" | ||
"github.com/honeydipper/honeydipper/pkg/dipper" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func createPVC(m *dipper.Message) { | ||
k8sclient := prepareKubeConfig(m) | ||
nameSpace, ok := dipper.GetMapDataStr(m.Payload, "namespace") | ||
if !ok { | ||
nameSpace = DefaultNamespace | ||
} | ||
|
||
pvc := corev1.PersistentVolumeClaim{} | ||
source := dipper.MustGetMapData(m.Payload, "pvc") | ||
buf, err := yaml.Marshal(source) | ||
if err != nil { | ||
log.Panicf("[%s] unable to marshal pvc manifest %+v", driver.Service, err) | ||
} | ||
err = yaml.Unmarshal(buf, &pvc) | ||
if err != nil { | ||
log.Panicf("[%s] invalid pvc manifest %+v", driver.Service, err) | ||
} | ||
|
||
client := k8sclient.CoreV1().PersistentVolumeClaims(nameSpace) | ||
ctx, cancel := driver.GetContext() | ||
defer cancel() | ||
pvcResult, e := client.Create(ctx, &pvc, metav1.CreateOptions{}) | ||
if e != nil { | ||
log.Panicf("[%s] failed to create pvc %+v", driver.Service, e) | ||
} | ||
|
||
m.Reply <- dipper.Message{ | ||
Payload: map[string]interface{}{ | ||
"metadata": pvcResult.ObjectMeta, | ||
"status": pvcResult.Status, | ||
}, | ||
} | ||
} | ||
|
||
func deletePVC(m *dipper.Message) { | ||
k8sclient := prepareKubeConfig(m) | ||
nameSpace, ok := dipper.GetMapDataStr(m.Payload, "namespace") | ||
if !ok { | ||
nameSpace = DefaultNamespace | ||
} | ||
pvcName := dipper.MustGetMapDataStr(m.Payload, "pvc") | ||
|
||
client := k8sclient.CoreV1().PersistentVolumeClaims(nameSpace) | ||
ctx, cancel := driver.GetContext() | ||
defer cancel() | ||
e := client.Delete(ctx, pvcName, metav1.DeleteOptions{}) | ||
if e != nil { | ||
log.Panicf("[%s] failed to delete pvc %+v", driver.Service, e) | ||
} | ||
|
||
m.Reply <- dipper.Message{} | ||
} |