mirror of
https://github.com/danielgormly/drone-plugin-kube.git
synced 2026-06-04 10:14:53 +08:00
Config map wip
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
appv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
// CreateConfigMapObj -- Construct ConfigMap ready json from YAML definition file
|
||||
func CreateConfigMapObj(yaml string) *appv1.ConfigMap {
|
||||
configMap := appv1.ConfigMap{}
|
||||
scheme.Codecs.UniversalDeserializer().Decode([]byte(yaml), nil, &configMap)
|
||||
return &configMap
|
||||
}
|
||||
|
||||
// CreateDeployment -- Updates given deployment in Kubernetes
|
||||
func CreateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Create(deployment)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
appv1 "k8s.io/api/apps/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
)
|
||||
|
||||
// CreateDeploymentObj -- Construct KubeClient ready json from YAML definition file
|
||||
func CreateDeploymentObj(yaml string) *appv1.Deployment {
|
||||
deployment := appv1.Deployment{}
|
||||
scheme.Codecs.UniversalDeserializer().Decode([]byte(yaml), nil, &deployment)
|
||||
return &deployment
|
||||
}
|
||||
|
||||
// UpdateDeployment -- Updates given deployment in Kubernetes
|
||||
func UpdateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Update(deployment)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateDeployment -- Updates given deployment in Kubernetes
|
||||
func CreateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Create(deployment)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeploymentExists -- Updates given deployment in Kubernetes
|
||||
func DeploymentExists(clientset *kubernetes.Clientset, namespace string, deploymentName string) (bool, error) {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Get(deploymentName, meta.GetOptions{})
|
||||
if err != nil {
|
||||
// TODO: Only conver to StatusError if the error is in fact a status error
|
||||
statusError, ok := err.(*errors.StatusError)
|
||||
if ok == true && statusError.Status().Code == 404 {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
@@ -5,11 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
appv1 "k8s.io/api/apps/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
)
|
||||
@@ -50,46 +46,3 @@ func (p Plugin) CreateKubeClient() (*kubernetes.Clientset, error) {
|
||||
}
|
||||
return kubernetes.NewForConfig(actualCfg)
|
||||
}
|
||||
|
||||
// CreateDeploymentObj -- Construct KubeClient ready json from YAML definition file
|
||||
func CreateDeploymentObj(yaml string) *appv1.Deployment {
|
||||
deployment := appv1.Deployment{}
|
||||
scheme.Codecs.UniversalDeserializer().Decode([]byte(yaml), nil, &deployment)
|
||||
return &deployment
|
||||
}
|
||||
|
||||
// UpdateDeployment -- Updates given deployment in Kubernetes
|
||||
func UpdateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Update(deployment)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateDeployment -- Updates given deployment in Kubernetes
|
||||
func CreateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Create(deployment)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeploymentExists -- Updates given deployment in Kubernetes
|
||||
func DeploymentExists(clientset *kubernetes.Clientset, namespace string, deploymentName string) (bool, error) {
|
||||
_, err := clientset.AppsV1().Deployments(namespace).Get(deploymentName, meta.GetOptions{})
|
||||
if err != nil {
|
||||
// TODO: Only conver to StatusError if the error is in fact a status error
|
||||
statusError, ok := err.(*errors.StatusError)
|
||||
if ok == true && statusError.Status().Code == 404 {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ListDeployments -- List deployments in Kubernetes
|
||||
// func ListDeployments(clientset *kubernetes.Clientset, namespace string) {
|
||||
// deployments, err := clientset.AppsV1().Deployments(namespace).List(v1.ListOptions{})
|
||||
// if err != nil {
|
||||
// log.Fatal(err.Error())
|
||||
// }
|
||||
// fmt.Println(deployments.Items)
|
||||
// // return deployments.Items
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
apiVersion: apps/v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{name}}
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: {{name}}
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: {{name}}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: 10.0.0.24:443/test:example.{{commit}}
|
||||
ports:
|
||||
- containerPort: 80
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
Reference in New Issue
Block a user