-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathcontainer_registry_index.go
50 lines (45 loc) · 1.19 KB
/
container_registry_index.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
package entrypoint
import (
"context"
"github.com/google/go-containerregistry/pkg/authn/k8schain"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
type containerRegistryIndex struct {
kubernetesClient kubernetes.Interface
}
func (i *containerRegistryIndex) Lookup(ctx context.Context, image string, options Options) (*Image, error) {
kc, err := k8schain.New(ctx, i.kubernetesClient, k8schain.Options{
Namespace: options.Namespace,
ServiceAccountName: options.ServiceAccountName,
ImagePullSecrets: imagePullSecretNames(options.ImagePullSecrets),
})
if err != nil {
return nil, err
}
ref, err := name.ParseReference(image)
if err != nil {
return nil, err
}
img, err := remote.Image(ref, remote.WithAuthFromKeychain(kc))
if err != nil {
return nil, err
}
f, err := img.ConfigFile()
if err != nil {
return nil, err
}
return &Image{
Entrypoint: f.Config.Entrypoint,
Cmd: f.Config.Cmd,
}, nil
}
func imagePullSecretNames(secrets []v1.LocalObjectReference) []string {
var v []string
for _, s := range secrets {
v = append(v, s.Name)
}
return v
}