cli-playground / kodo

MIT License
0 stars 6 forks source link

Add a command to deploy an image #11

Closed sbose78 closed 4 years ago

sbose78 commented 4 years ago

As a user I should be able to use the below command to deploy an image.

kodo deploy --image=openshift/hello-openshift:latest --replicas=10 --port=80 --token=xyz --server=https://url  --n=mynamespace

Behind the scenes, this should create a new Deployment .

Something similar to this should be created

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-openshift
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-openshift
  template:
    metadata:
      labels:
        app: hello-openshift
    spec:
      containers:
      - name: hello-openshift
        image: openshift/hello-openshift:latest
        ports:
        - containerPort: 80

You don't necessarily need to write a yaml, you could create a instance of the Deployment struct, and then call the API to create this Deployment.

Usage hint

go get k8s.io/api@v0.18.3
import "k8s.io/api/core/v1"
import appsv1 "k8s.io/api/apps/v1" //  alias this as appsv1
...
...
...

deploymentObj := &appsv1.Deployment{
        ObjectMeta: metav1.ObjectMeta{
            Name: "some-unique-name",
        },
        Spec: appsv1.DeploymentSpec{
            Replicas: &replicas, 
            Selector: &metav1.LabelSelector{
                MatchLabels: map[string]string{
                    "app": "some-unique-name",
                },
            },
            Template: apiv1.PodTemplateSpec{
                ObjectMeta: metav1.ObjectMeta{
                    Labels: map[string]string{
                        "some-unique-name", 
                    },
                },
                Spec: apiv1.PodSpec{
                    Containers: []apiv1.Container{
                        {
                            Name:  "doesnt-matteer",
                            Image: "image-to-be-deployed", // should come from flag
                            Ports: []apiv1.ContainerPort{
                                {
                                    Name:          "http",
                                    Protocol:      apiv1.ProtocolTCP,
                                    ContainerPort: 80, // should come from flag
                                },
                            },
                        },
                    },
                },
            },
        },
    }
    clientset.AppsV1().Deployments(NAMESPACE).Create(deploymentObj)