1
1
package packager
2
2
3
3
import (
4
+ "crypto/sha256"
4
5
"fmt"
5
6
"io/ioutil"
6
7
"os"
@@ -31,6 +32,7 @@ func runInjectionMadness(tempPath tempPaths) {
31
32
var images []string
32
33
var envVars []corev1.EnvVar
33
34
var payloadConfigmaps []string
35
+ var sha256sum string
34
36
35
37
// Try to create the zarf namespace
36
38
spinner .Updatef ("Creating the Zarf namespace" )
@@ -62,7 +64,7 @@ func runInjectionMadness(tempPath tempPaths) {
62
64
}
63
65
64
66
spinner .Updatef ("Loading the seed registry configmaps" )
65
- if payloadConfigmaps , err = createPayloadConfigmaps (tempPath , spinner ); err != nil {
67
+ if payloadConfigmaps , sha256sum , err = createPayloadConfigmaps (tempPath , spinner ); err != nil {
66
68
message .Fatal (err , "Unable to generate the injector payload configmaps" )
67
69
}
68
70
@@ -82,7 +84,7 @@ func runInjectionMadness(tempPath tempPaths) {
82
84
_ = k8s .DeletePod (k8s .ZarfNamespace , "injector" )
83
85
84
86
// Update the podspec image path
85
- pod := buildInjectionPod (image , envVars , payloadConfigmaps )
87
+ pod := buildInjectionPod (image , envVars , payloadConfigmaps , sha256sum )
86
88
87
89
// Create the pod in the cluster
88
90
pod , err = k8s .CreatePod (pod )
@@ -103,13 +105,14 @@ func runInjectionMadness(tempPath tempPaths) {
103
105
spinner .Fatalf (nil , "Unable to perform the injection" )
104
106
}
105
107
106
- func createPayloadConfigmaps (tempPath tempPaths , spinner * message.Spinner ) ([]string , error ) {
108
+ func createPayloadConfigmaps (tempPath tempPaths , spinner * message.Spinner ) ([]string , string , error ) {
107
109
message .Debugf ("packager.tryInjectorPayloadDeploy(%v)" , tempPath )
108
110
var (
109
111
err error
110
112
tarFile []byte
111
113
chunks [][]byte
112
114
configMaps []string
115
+ sha256sum string
113
116
)
114
117
115
118
// Chunk size has to accomdate base64 encoding & etcd 1MB limit
@@ -125,14 +128,19 @@ func createPayloadConfigmaps(tempPath tempPaths, spinner *message.Spinner) ([]st
125
128
spinner .Updatef ("Creating the seed registry archive to send to the cluster" )
126
129
// Create a tar archive of the injector payload
127
130
if err = archiver .Archive (tarFileList , tarPath ); err != nil {
128
- return configMaps , err
131
+ return configMaps , "" , err
129
132
}
130
133
134
+ archiver .Archive (tarFileList , "/home/user/payload.tgz" )
135
+
131
136
// Open the created archive for io.Copy
132
137
if tarFile , err = ioutil .ReadFile (tarPath ); err != nil {
133
- return configMaps , err
138
+ return configMaps , "" , err
134
139
}
135
140
141
+ //Calculate the sha256sum of the tarFile before we split it up
142
+ sha256sum = fmt .Sprintf ("%x" , sha256 .Sum256 (tarFile ))
143
+
136
144
spinner .Updatef ("Splitting the archive into binary configmaps" )
137
145
// Loop over the tarball breaking it into chunks based on the payloadChunkSize
138
146
for {
@@ -165,7 +173,7 @@ func createPayloadConfigmaps(tempPath tempPaths, spinner *message.Spinner) ([]st
165
173
166
174
// Attempt to create the configmap in the cluster
167
175
if _ , err = k8s .ReplaceConfigmap (k8s .ZarfNamespace , fileName , labels , configData ); err != nil {
168
- return configMaps , err
176
+ return configMaps , "" , err
169
177
}
170
178
171
179
// Add the configmap to the configmaps slice for later usage in the pod
@@ -175,7 +183,7 @@ func createPayloadConfigmaps(tempPath tempPaths, spinner *message.Spinner) ([]st
175
183
time .Sleep (100 * time .Millisecond )
176
184
}
177
185
178
- return configMaps , nil
186
+ return configMaps , sha256sum , nil
179
187
}
180
188
181
189
func hasSeedImages (spinner * message.Spinner ) bool {
@@ -295,21 +303,20 @@ func buildEnvVars(tempPath tempPaths) ([]corev1.EnvVar, error) {
295
303
}
296
304
297
305
// buildInjectionPod return a pod for injection with the appropriate containers to perform the injection
298
- func buildInjectionPod (image string , envVars []corev1.EnvVar , payloadConfigmaps []string ) * corev1.Pod {
306
+ func buildInjectionPod (image string , envVars []corev1.EnvVar , payloadConfigmaps []string , payloadShasum string ) * corev1.Pod {
299
307
pod := k8s .GeneratePod ("injector" , k8s .ZarfNamespace )
300
308
executeMode := int32 (0777 )
301
309
seedImage := config .GetSeedImage ()
302
310
303
311
pod .Labels ["app" ] = "zarf-injector"
304
312
305
313
pod .Spec .RestartPolicy = corev1 .RestartPolicyNever
306
-
307
314
pod .Spec .InitContainers = []corev1.Container {
308
315
{
309
316
Name : "init-injector" ,
310
317
Image : image ,
311
318
WorkingDir : "/zarf-stage1" ,
312
- Command : []string {"/zarf-stage1/zarf-injector" },
319
+ Command : []string {"/zarf-stage1/zarf-injector" , payloadShasum },
313
320
314
321
VolumeMounts : []corev1.VolumeMount {
315
322
{
0 commit comments