-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.go
51 lines (46 loc) · 1.26 KB
/
images.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package deployments
import (
"fmt"
"strings"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"github.com/angelokurtis/kts-cli/internal/log"
"github.com/angelokurtis/kts-cli/pkg/app/kubectl"
)
// kube deployments update-images
func updateImages(cmd *cobra.Command, args []string) {
deploys, err := kubectl.ListDeployments(namespace, allNamespaces)
if err != nil {
log.Fatal(err)
}
deploys, err = deploys.SelectMany()
if err != nil {
log.Fatal(err)
}
containers, err := deploys.SelectContainers()
if err != nil {
log.Fatal(err)
}
tag := ""
prompt := &survey.Input{Message: "Inform the new tag:"}
err = survey.AskOne(prompt, &tag, survey.WithKeepFilter(true))
if err != nil {
log.Fatal(err)
}
for _, deploy := range deploys.Items {
for _, container := range deploy.Spec.Template.Spec.Containers {
if containers.Contains(container.Name) {
updateImage(deploy, container, tag)
}
}
}
}
func updateImage(deploy *kubectl.Deployment, container *kubectl.Container, tag string) {
c := deploy.GetContainer(container.Name)
if c != nil {
name := deploy.Metadata.Name
ns := deploy.Metadata.Namespace
image := strings.Split(c.Image, ":")[0]
fmt.Printf("kubectl set image deployment/%s %s=%s:%s -n %s\n", name, c.Name, image, tag, ns)
}
}