Skip to content

Commit

Permalink
move all installs to v2 (#1772)
Browse files Browse the repository at this point in the history
* rename install2 command to install, install to install-legacy

* test disabling operator overrides

* handle reworking map[interface{}]interface{} properly

* get then update status

* remove chart apply

* f
  • Loading branch information
laverya authored Jan 30, 2025
1 parent 8100822 commit 24433e6
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/installer/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
)

cmd := &cobra.Command{
Use: "install",
Use: "install-legacy",
Short: fmt.Sprintf("Install %s", name),
SilenceErrors: true,
SilenceUsage: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/cli/install2.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Install2Cmd(ctx context.Context, name string) *cobra.Command {
var flags Install2CmdFlags

cmd := &cobra.Command{
Use: "install2",
Use: "install",
Short: fmt.Sprintf("Experimental installer for %s", name),
Hidden: true,
SilenceUsage: true,
Expand Down
37 changes: 18 additions & 19 deletions operator/controllers/installation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
ectypes "github.com/replicatedhq/embedded-cluster/kinds/types"
"github.com/replicatedhq/embedded-cluster/operator/pkg/autopilot"
"github.com/replicatedhq/embedded-cluster/operator/pkg/charts"
"github.com/replicatedhq/embedded-cluster/operator/pkg/k8sutil"
"github.com/replicatedhq/embedded-cluster/operator/pkg/metrics"
"github.com/replicatedhq/embedded-cluster/operator/pkg/openebs"
Expand Down Expand Up @@ -620,24 +619,24 @@ func (r *InstallationReconciler) Reconcile(ctx context.Context, req ctrl.Request
return ctrl.Result{}, fmt.Errorf("failed to reconcile openebs: %w", err)
}

// reconcile helm chart dependencies including secrets.
if err := r.ReconcileRegistry(ctx, in); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to pre-reconcile helm charts: %w", err)
}

// reconcile the add-ons (k0s helm extensions).
log.Info("Reconciling helm charts")
ev, err := charts.ReconcileHelmCharts(ctx, r.Client, in)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile helm charts: %w", err)
}
if ev != nil {
r.Recorder.Event(in, corev1.EventTypeNormal, ev.Reason, ev.Message)
}

if err := r.ReconcileHAStatus(ctx, in); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to reconcile HA status: %w", err)
}
//// reconcile helm chart dependencies including secrets.
//if err := r.ReconcileRegistry(ctx, in); err != nil {
// return ctrl.Result{}, fmt.Errorf("failed to pre-reconcile helm charts: %w", err)
//}
//
//// reconcile the add-ons (k0s helm extensions).
//log.Info("Reconciling helm charts")
//ev, err := charts.ReconcileHelmCharts(ctx, r.Client, in)
//if err != nil {
// return ctrl.Result{}, fmt.Errorf("failed to reconcile helm charts: %w", err)
//}
//if ev != nil {
// r.Recorder.Event(in, corev1.EventTypeNormal, ev.Reason, ev.Message)
//}

//if err := r.ReconcileHAStatus(ctx, in); err != nil {
// return ctrl.Result{}, fmt.Errorf("failed to reconcile HA status: %w", err)
//}

// save the installation status. nothing more to do with it.
if err := r.Status().Update(ctx, in.DeepCopy()); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ func cleanUpMapValue(v interface{}) interface{} {
case []interface{}:
return cleanUpInterfaceArray(v)
case map[string]interface{}:
return cleanUpGenericMap(v)
case map[interface{}]interface{}:
return cleanUpInterfaceMap(v)
case string:
return v
Expand All @@ -577,7 +579,7 @@ func cleanUpInterfaceArray(in []interface{}) []interface{} {
}

// Cleans up the map keys to be strings
func cleanUpInterfaceMap(in map[string]interface{}) map[string]interface{} {
func cleanUpInterfaceMap(in map[interface{}]interface{}) map[string]interface{} {
result := make(map[string]interface{})
for k, v := range in {
result[fmt.Sprintf("%v", k)] = cleanUpMapValue(v)
Expand Down
92 changes: 92 additions & 0 deletions pkg/helm/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package helm

import (
"github.com/stretchr/testify/require"
"testing"
)

func Test_cleanUpGenericMap(t *testing.T) {
tests := []struct {
name string
in map[string]interface{}
want map[string]interface{}
}{
{
name: "single level map",
in: map[string]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
want: map[string]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
},
{
name: "nested map, string keys",
in: map[string]interface{}{
"nest": map[string]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
},
want: map[string]interface{}{
"nest": map[string]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
},
},
{
name: "nested map, interface keys", // this is what would fail previously
in: map[string]interface{}{
"nest": map[interface{}]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
},
want: map[string]interface{}{
"nest": map[string]interface{}{
"abc": "xyz",
"number": 5,
"float": 1.5,
"bool": true,
"array": []interface{}{
"element",
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := require.New(t)
req.Equal(tt.want, cleanUpGenericMap(tt.in))
})
}
}
9 changes: 8 additions & 1 deletion pkg/kubeutils/kubeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ func UpdateInstallation(ctx context.Context, cli client.Client, in *ecv1beta1.In
func UpdateInstallationStatus(ctx context.Context, cli client.Client, in *ecv1beta1.Installation) error {
// if the installation source type is CRD (or not set), just update directly
if in.Spec.SourceType == "" || in.Spec.SourceType == ecv1beta1.InstallationSourceTypeCRD {
if err := cli.Status().Update(ctx, in); err != nil {
updatedCRD := ecv1beta1.Installation{}
err := cli.Get(ctx, types.NamespacedName{Name: in.Name, Namespace: in.Namespace}, &updatedCRD)
if err != nil {
return fmt.Errorf("get crd installation before updating status: %w", err)
}
updatedCRD.Status = in.Status
err = cli.Status().Update(ctx, &updatedCRD)
if err != nil {
return fmt.Errorf("update crd installation status: %w", err)
}
return nil
Expand Down

0 comments on commit 24433e6

Please sign in to comment.