Skip to content

Commit

Permalink
fix kotsadm installation params for embedded clusters (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Aug 3, 2021
1 parent adfe01a commit b6e9a2c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
34 changes: 28 additions & 6 deletions pkg/kotsadm/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ func getConfigMapsYAML(deployOptions types.DeployOptions) (map[string][]byte, er
docs := map[string][]byte{}
s := json.NewYAMLSerializer(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme)

var configMap bytes.Buffer
if err := s.Encode(kotsadmobjects.KotsadmConfigMap(deployOptions), &configMap); err != nil {
return nil, errors.Wrap(err, "failed to marshal minio config map")
var kotsadmConfigMap bytes.Buffer
if err := s.Encode(kotsadmobjects.KotsadmConfigMap(deployOptions), &kotsadmConfigMap); err != nil {
return nil, errors.Wrap(err, "failed to marshal kotsadm config map")
}
docs["kotsadm-config.yaml"] = configMap.Bytes()
docs["kotsadm-config.yaml"] = kotsadmConfigMap.Bytes()

var postgresConfigMap bytes.Buffer
if err := s.Encode(kotsadmobjects.PostgresConfigMap(deployOptions), &postgresConfigMap); err != nil {
return nil, errors.Wrap(err, "failed to marshal postgres config map")
}
docs["postgres-config.yaml"] = postgresConfigMap.Bytes()

return docs, nil
}
Expand All @@ -44,21 +50,37 @@ func ensureKotsadmConfig(deployOptions types.DeployOptions, clientset *kubernete
}

func ensureConfigMaps(deployOptions types.DeployOptions, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Get(context.TODO(), types.KotsadmConfigMap, metav1.GetOptions{})
desiredConfigMap := kotsadmobjects.KotsadmConfigMap(deployOptions)

existingConfigMap, err := clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Get(context.TODO(), types.KotsadmConfigMap, metav1.GetOptions{})
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
return errors.Wrap(err, "failed to get existing kotsadm config map")
}

_, err := clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Create(context.TODO(), kotsadmobjects.KotsadmConfigMap(deployOptions), metav1.CreateOptions{})
_, err := clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Create(context.TODO(), desiredConfigMap, metav1.CreateOptions{})
if err != nil {
return errors.Wrap(err, "failed to create kotsadm config map")
}

return nil
}

existingConfigMap = updateConfigMap(existingConfigMap, desiredConfigMap)

_, err = clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Update(context.TODO(), existingConfigMap, metav1.UpdateOptions{})
if err != nil {
return errors.Wrap(err, "failed to update kotsadm config map")
}

return nil
}

func updateConfigMap(existingConfigMap, desiredConfigMap *corev1.ConfigMap) *corev1.ConfigMap {
existingConfigMap.Data = desiredConfigMap.Data
return existingConfigMap
}

func ensurePostgresConfigMap(deployOptions types.DeployOptions, clientset *kubernetes.Clientset) error {
_, err := clientset.CoreV1().ConfigMaps(deployOptions.Namespace).Get(context.TODO(), "kotsadm-postgres", metav1.GetOptions{})
if err == nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/kotsadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ func YAML(deployOptions types.DeployOptions) (map[string][]byte, error) {
docs[n] = v
}

// configmaps
configMapsDocs, err := getConfigMapsYAML(deployOptions)
if err != nil {
return nil, errors.Wrap(err, "failed to get configmaps yaml")
}
for n, v := range configMapsDocs {
docs[n] = v
}

// kotsadm
kotsadmDocs, err := getKotsadmYAML(deployOptions)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/kotsadm/objects/configmaps_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func KotsadmConfigMap(deployOptions types.DeployOptions) *corev1.ConfigMap {
"initial-app-images-pushed": fmt.Sprintf("%v", deployOptions.AppImagesPushed),
"skip-preflights": fmt.Sprintf("%v", deployOptions.SkipPreflights),
"registry-is-read-only": fmt.Sprintf("%v", deployOptions.DisableImagePush),
"enable-image-deletion": fmt.Sprintf("%v", deployOptions.EnableImageDeletion),
}
if kotsadmversion.KotsadmPullSecret(deployOptions.Namespace, deployOptions.KotsadmOptions) != nil {
data["kotsadm-registry"] = kotsadmversion.KotsadmRegistry(deployOptions.KotsadmOptions)
Expand Down
1 change: 0 additions & 1 deletion pkg/kotsadm/types/deployoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type DeployOptions struct {
InstallID string
SimultaneousUploads int
DisableImagePush bool
EnableImageDeletion bool
UpstreamURI string

IdentityConfig kotsv1beta1.IdentityConfig
Expand Down
2 changes: 1 addition & 1 deletion pkg/kotsutil/kots.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ func GetInstallationParams(configMapName string) (InstallationParams, error) {
autoConfig.SkipImagePush, _ = strconv.ParseBool(kotsadmConfigMap.Data["initial-app-images-pushed"])
autoConfig.SkipPreflights, _ = strconv.ParseBool(kotsadmConfigMap.Data["skip-preflights"])
autoConfig.RegistryIsReadOnly, _ = strconv.ParseBool(kotsadmConfigMap.Data["registry-is-read-only"])
autoConfig.EnableImageDeletion, _ = strconv.ParseBool(kotsadmConfigMap.Data["enable-image-deletion"])
autoConfig.EnableImageDeletion = IsKurl(clientset)

return autoConfig, nil
}
Expand Down

0 comments on commit b6e9a2c

Please sign in to comment.