This commit is contained in:
Daniel
2019-06-14 13:01:43 +10:00
parent baba219ca8
commit 7be925d54c
4 changed files with 30 additions and 12 deletions
+1 -1
View File
@@ -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
View File
@@ -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
}
+3 -2
View File
@@ -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"))
+13 -4
View File
@@ -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
}