calling the deployment yaml through client go examples

7/22/2019

I am trying to call the update deployment through the client go for k8. But I am having hard time update the changes from deployment.yaml file any code examples for an equivalent to kubectl apply -f deployment.yaml through the client-go APIs

-- bala krishna
client-go
kubernetes

1 Answer

7/22/2019

This example program demonstrates the fundamental operations for managing on Deployment resources, such as Create, List, Update and Delete.

Code for this is available here and the whole documentation for Go client for Kubernetes..

Or you can just write your own function to deploy the yaml as a parameter.

func cellDeploy(pathToFileName string) error {
    cmd := exec.Command("kubectl", "apply", "-f", pathToFileName)
    stdoutReader, _ := cmd.StdoutPipe()
    stdoutScanner := bufio.NewScanner(stdoutReader)
    go func() {
        for stdoutScanner.Scan() {
            fmt.Println(stdoutScanner.Text())
        }
    }()
    stderrReader, _ := cmd.StderrPipe()
    stderrScanner := bufio.NewScanner(stderrReader)
    go func() {
        for stderrScanner.Scan() {
            fmt.Println(stderrScanner.Text())
        }
    }()
    err := cmd.Start()
    if err != nil {
        fmt.Printf("Error : %v \n", err)
        os.Exit(1)
    }
    err = cmd.Wait()
    if err != nil {
        fmt.Printf("Error: %v \n", err)
        os.Exit(1)
    }

    return nil
}
-- Crou
Source: StackOverflow