mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-04 18:23:48 +08:00
wip
This commit is contained in:
@@ -28,7 +28,7 @@ Deployment config files are first interpreted by **aymerick/raymond** ([handleba
|
||||
|
||||
## Config maps from files
|
||||
|
||||
In this case
|
||||
In this case, you can create a template just like deployment.yaml but you can provide a file path (relative to the repo's root) in the plugin setting `configmap_file`.
|
||||
|
||||
#### Adding a service account to Kubernetes that can manage deployments
|
||||
See [example/Role.yaml](example/Role.yaml), [example/ServiceAccount.yaml](example/ServiceAccount.yaml), [example/RoleBinding.yaml](example/RoleBinding.yaml).
|
||||
|
||||
+13
-5
@@ -1,13 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
appv1 "k8s.io/api/core/v1"
|
||||
"io/ioutil"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
// CreateConfigMap -- Updates given deployment in Kubernetes
|
||||
func CreateConfigMapFromFile(clientset *kubernetes.Clientset, namespace string, name string) error {
|
||||
configMap := appv1.ConfigMap{}
|
||||
_, err := clientset.AppsV1().ConfigMap(namespace).Create(configMap)
|
||||
// ApplyConfigMapFromFile -- Updates given deployment in Kubernetes
|
||||
func ApplyConfigMapFromFile(clientset *kubernetes.Clientset, namespace string, configmap *corev1.ConfigMap, path string) error {
|
||||
fileContents, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
configMapData := make(map[string][]byte)
|
||||
configMapData["notsure"] = fileContents
|
||||
configmap.BinaryData = configMapData
|
||||
_, err = clientset.CoreV1().ConfigMaps(namespace).Create(configmap)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
|
||||
func main() {
|
||||
plugin := Plugin{
|
||||
Template: os.Getenv("PLUGIN_TEMPLATE"),
|
||||
Template: os.Getenv("PLUGIN_TEMPLATE"),
|
||||
ConfigMapFile: os.Getenv("PLUGIN_CONFIGMAP_FILE"),
|
||||
KubeConfig: KubeConfig{
|
||||
Token: os.Getenv("PLUGIN_TOKEN"),
|
||||
Server: os.Getenv("PLUGIN_SERVER"),
|
||||
Ca: os.Getenv("PLUGIN_CA"),
|
||||
Namespace: os.Getenv("PLUGIN_NAMESPACE"),
|
||||
InsecureSkipTLSVerify: os.Getenv("PLUGIN_SKIP_TLS") == "false",
|
||||
InsecureSkipTLSVerify: os.Getenv("PLUGIN_SKIP_TLS") == "false", // TODO: coerce from JSON true false into bool
|
||||
},
|
||||
}
|
||||
fmt.Printf(os.Getenv("PLUGIN_SKIP_TLS"))
|
||||
|
||||
@@ -25,8 +25,9 @@ type (
|
||||
}
|
||||
// Plugin -- Contains config for plugin
|
||||
Plugin struct {
|
||||
Template string
|
||||
KubeConfig KubeConfig
|
||||
Template string
|
||||
KubeConfig KubeConfig
|
||||
ConfigMapFile string // Optional
|
||||
}
|
||||
)
|
||||
|
||||
@@ -76,11 +77,19 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
// Decode
|
||||
kubernetesObject, _, err := scheme.Codecs.UniversalDeserializer().Decode([]byte(templateYaml), nil, nil)
|
||||
if err != nil {
|
||||
log.Print("⛔️ Error decoding template into valid Kubernetes object:")
|
||||
return err
|
||||
}
|
||||
|
||||
switch o := kubernetesObject.(type) {
|
||||
case *appv1.Deployment:
|
||||
CreateOrUpdateDeployment(clientset, p.KubeConfig.Namespace, o)
|
||||
err = CreateOrUpdateDeployment(clientset, p.KubeConfig.Namespace, o)
|
||||
case *corev1.ConfigMap:
|
||||
CreateOrUpdateConfigMap(clientset, p.KubeConfig.Namespace, o)
|
||||
err = ApplyConfigMapFromFile(clientset, p.KubeConfig.Namespace, o, p.ConfigMapFile)
|
||||
default:
|
||||
err = errors.New("⛔️ This plugin doesn't support that kind of Kubernetes object")
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user