4
4
"context"
5
5
"fmt"
6
6
"os/exec"
7
+ "path"
7
8
8
9
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
9
10
"k8s.io/utils/ptr"
@@ -18,14 +19,15 @@ const (
18
19
debug = "--debug"
19
20
skipTLS = "--dest-tls-verify=false"
20
21
skipCreds = "--dest-no-creds=true"
21
- destCreds = "--dest-creds ="
22
+ destCreds = "--dest-authfile ="
22
23
v2format = "--format=v2s2"
23
- skopeoImage = "quay.io/olmtest/ skopeo:0.1.40 "
24
+ skopeoImage = "quay.io/skopeo/stable:v1.15.0 "
24
25
BuilderServiceAccount = "builder"
26
+ authPath = "/mnt/registry-auth"
27
+ cachePath = ".local"
25
28
)
26
29
27
- func openshiftRegistryAuth (client operatorclient.ClientInterface , namespace string ) (string , error ) {
28
-
30
+ func getRegistryAuthSecretName (client operatorclient.ClientInterface , namespace string ) (string , error ) {
29
31
var sa * corev1.ServiceAccount
30
32
var err error
31
33
@@ -47,15 +49,7 @@ func openshiftRegistryAuth(client operatorclient.ClientInterface, namespace stri
47
49
if err != nil {
48
50
return "" , err
49
51
}
50
- annotations := secret .Annotations
51
- if annotations == nil {
52
- return "" , fmt .Errorf ("annotations not present on builder secret" )
53
- }
54
-
55
- user := annotations ["openshift.io/token-secret.name" ]
56
- pass := annotations ["openshift.io/token-secret.value" ]
57
-
58
- return fmt .Sprint (user , ":" , pass ), nil
52
+ return secret .GetName (), nil
59
53
}
60
54
61
55
func skopeoCopyCmd (newImage , newTag , oldImage , oldTag , auth string ) []string {
@@ -66,15 +60,15 @@ func skopeoCopyCmd(newImage, newTag, oldImage, oldTag, auth string) []string {
66
60
if auth == "" {
67
61
creds = skipCreds
68
62
} else {
69
- creds = fmt .Sprint (destCreds , auth )
63
+ creds = fmt .Sprint (destCreds , path . Join ( cachePath , " auth.json" ) )
70
64
}
71
65
72
66
cmd := []string {debug , insecure , "copy" , skipTLS , v2format , creds , oldImageName , newImageName }
73
67
74
68
return cmd
75
69
}
76
70
77
- func createSkopeoPod (client operatorclient.ClientInterface , args []string , namespace string ) error {
71
+ func createSkopeoPod (client operatorclient.ClientInterface , args []string , namespace string , registrySecret string ) error {
78
72
pod := & corev1.Pod {
79
73
ObjectMeta : metav1.ObjectMeta {
80
74
Name : skopeo ,
@@ -93,12 +87,12 @@ func createSkopeoPod(client operatorclient.ClientInterface, args []string, names
93
87
Image : skopeoImage ,
94
88
Args : args ,
95
89
SecurityContext : & corev1.SecurityContext {
96
- ReadOnlyRootFilesystem : ptr .To (bool ( false ) ),
97
- AllowPrivilegeEscalation : ptr .To (bool ( false ) ),
90
+ ReadOnlyRootFilesystem : ptr .To (false ),
91
+ AllowPrivilegeEscalation : ptr .To (false ),
98
92
Capabilities : & corev1.Capabilities {
99
93
Drop : []corev1.Capability {"ALL" },
100
94
},
101
- RunAsNonRoot : ptr .To (bool ( true ) ),
95
+ RunAsNonRoot : ptr .To (true ),
102
96
RunAsUser : ptr .To (int64 (1001 )),
103
97
},
104
98
},
@@ -108,6 +102,43 @@ func createSkopeoPod(client operatorclient.ClientInterface, args []string, names
108
102
},
109
103
}
110
104
105
+ if registrySecret != "" {
106
+ // update container command to first convert the dockercfg to an auth.json file that skopeo can use
107
+ authJsonPath := path .Join (cachePath , "auth.json" )
108
+ authJson := "\" {\\ \" auths\\ \" : $(cat /mnt/registry-auth/.dockercfg)}\" "
109
+ cmd := fmt .Sprintf ("echo %s > %s && exec skopeo $@" , authJson , authJsonPath )
110
+
111
+ pod .Spec .Containers [0 ].Command = []string {"bash" , "-c" , cmd }
112
+
113
+ pod .Spec .Containers [0 ].VolumeMounts = []corev1.VolumeMount {
114
+ {
115
+ Name : "registry-auth" ,
116
+ MountPath : authPath ,
117
+ ReadOnly : true ,
118
+ }, {
119
+ Name : "cache" ,
120
+ MountPath : cachePath ,
121
+ ReadOnly : false ,
122
+ },
123
+ }
124
+ pod .Spec .Volumes = []corev1.Volume {
125
+ {
126
+ Name : "registry-auth" ,
127
+ VolumeSource : corev1.VolumeSource {
128
+ Secret : & corev1.SecretVolumeSource {
129
+ SecretName : registrySecret ,
130
+ },
131
+ },
132
+ },
133
+ {
134
+ Name : "cache" ,
135
+ VolumeSource : corev1.VolumeSource {
136
+ EmptyDir : & corev1.EmptyDirVolumeSource {},
137
+ },
138
+ },
139
+ }
140
+ }
141
+
111
142
_ , err := client .KubernetesInterface ().CoreV1 ().Pods (namespace ).Create (context .TODO (), pod , metav1.CreateOptions {})
112
143
if err != nil {
113
144
return err
0 commit comments