Skip to content

Commit

Permalink
Merge branch 'main' into remove/k8s-hpa
Browse files Browse the repository at this point in the history
  • Loading branch information
Noxsios committed May 23, 2024
2 parents 81a3b20 + 047cb35 commit 87d1906
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 84 deletions.
73 changes: 51 additions & 22 deletions src/pkg/cluster/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,24 @@ func (c *Cluster) StopInjectionMadness(ctx context.Context) error {
}

// Remove the configmaps
labelMatch := map[string]string{"zarf-injector": "payload"}
if err := c.DeleteConfigMapsByLabel(ctx, ZarfNamespaceName, labelMatch); err != nil {
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
MatchLabels: map[string]string{
"zarf-injector": "payload",
},
})
if err != nil {
return err
}
listOpts := metav1.ListOptions{
LabelSelector: selector.String(),
}
err = c.Clientset.CoreV1().ConfigMaps(ZarfNamespaceName).DeleteCollection(ctx, metav1.DeleteOptions{}, listOpts)
if err != nil {
return err
}

// Remove the injector service
err := c.Clientset.CoreV1().Services(ZarfNamespaceName).Delete(ctx, "zarf-injector", metav1.DeleteOptions{})
err = c.Clientset.CoreV1().Services(ZarfNamespaceName).Delete(ctx, "zarf-injector", metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down Expand Up @@ -231,16 +242,26 @@ func (c *Cluster) createPayloadConfigMaps(ctx context.Context, seedImagesDir, ta
// Create a cat-friendly filename
fileName := fmt.Sprintf("zarf-payload-%03d", idx)

// Store the binary data
configData := map[string][]byte{
fileName: data,
}

spinner.Updatef("Adding archive binary configmap %d of %d to the cluster", idx+1, chunkCount)

// Attempt to create the configmap in the cluster
if _, err = c.ReplaceConfigmap(ctx, ZarfNamespaceName, fileName, configData); err != nil {
return configMaps, "", err
// TODO: Replace with create or update.
err := c.Clientset.CoreV1().ConfigMaps(ZarfNamespaceName).Delete(ctx, fileName, metav1.DeleteOptions{})
if err != nil && !kerrors.IsNotFound(err) {
return nil, "", err
}
cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: fileName,
Namespace: ZarfNamespaceName,
},
BinaryData: map[string][]byte{
fileName: data,
},
}
_, err = c.Clientset.CoreV1().ConfigMaps(ZarfNamespaceName).Create(ctx, cm, metav1.CreateOptions{})
if err != nil {
return nil, "", err
}

// Add the configmap to the configmaps slice for later usage in the pod
Expand Down Expand Up @@ -291,22 +312,30 @@ func (c *Cluster) injectorIsReady(ctx context.Context, seedImages []transform.Im
}

func (c *Cluster) createInjectorConfigMap(ctx context.Context, binaryPath string) error {
var err error
configData := make(map[string][]byte)

// Add the injector binary data to the configmap
if configData["zarf-injector"], err = os.ReadFile(binaryPath); err != nil {
name := "rust-binary"
// TODO: Replace with a create or update.
err := c.Clientset.CoreV1().ConfigMaps(ZarfNamespaceName).Delete(ctx, name, metav1.DeleteOptions{})
if err != nil && !kerrors.IsNotFound(err) {
return err
}

// Try to delete configmap silently
_ = c.DeleteConfigmap(ctx, ZarfNamespaceName, "rust-binary")

// Attempt to create the configmap in the cluster
if _, err = c.CreateConfigmap(ctx, ZarfNamespaceName, "rust-binary", configData); err != nil {
b, err := os.ReadFile(binaryPath)
if err != nil {
return err
}
configData := map[string][]byte{
"zarf-injector": b,
}
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ZarfNamespaceName,
},
BinaryData: configData,
}
_, err = c.Clientset.CoreV1().ConfigMaps(configMap.Namespace).Create(ctx, configMap, metav1.CreateOptions{})
if err != nil {
return err
}

return nil
}

Expand Down
62 changes: 0 additions & 62 deletions src/pkg/k8s/configmap.go

This file was deleted.

0 comments on commit 87d1906

Please sign in to comment.