-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.go
74 lines (64 loc) · 1.78 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package commands
import (
"context"
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/ecr"
"github.com/tb0hdan/aws-k8s/pkg/commands/images"
"github.com/tb0hdan/aws-k8s/pkg/commands/kubectl"
"github.com/tb0hdan/aws-k8s/pkg/config"
"github.com/tb0hdan/aws-k8s/pkg/external"
)
type ImageCmd struct {
Arguments []string `arg:"" optional:"" name:"arguments" help:"Kubectl arguments"`
}
func (i *ImageCmd) Run(ctx *CLIContext) error {
var (
kubeGetPodsResponse images.GetPodsResponse
)
r := kubectl.New("~/.aws/aws-k8s-assume.json")
args := make([]string, 0, len(i.Arguments))
args = append(args, i.Arguments...)
args = append(args, []string{"get", "pods", "-o", "json"}...)
out, err := r.Run(args...)
if err != nil {
return err
}
err = json.Unmarshal([]byte(out), &kubeGetPodsResponse)
if err != nil {
return err
}
for _, item := range kubeGetPodsResponse.Items {
fmt.Println(item.Metadata.Name, item.Spec.Containers[0].Image)
}
//
appConfig := config.New("~/.aws/aws-k8s.ini")
appConfig.Load()
ecrClient := &external.ECRClient{AppConfig: appConfig}
client := ecrClient.Get()
repositories, err := client.Client.DescribeRepositories(context.Background(), &ecr.DescribeRepositoriesInput{
MaxResults: nil,
// NextToken: nil,
// RegistryId: nil,
// RepositoryNames: nil,
})
if err != nil {
return err
}
for _, repository := range repositories.Repositories {
images, err := client.Client.ListImages(context.Background(), &ecr.ListImagesInput{
RepositoryName: repository.RepositoryName,
// Filter: nil,
// MaxResults: nil,
// NextToken: nil,
// RegistryId: nil,
})
if err != nil {
continue
}
for _, image := range images.ImageIds {
fmt.Println(*image.ImageTag, *image.ImageDigest)
}
}
return nil
}