Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into danj/config-command
Browse files Browse the repository at this point in the history
  • Loading branch information
danj-replicated committed Jan 10, 2024
2 parents 9236596 + ca98066 commit 4ff8bc6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARCH := $(shell uname -m)
APP_NAME = embedded-cluster
ADMIN_CONSOLE_CHART_URL = oci://registry.replicated.com/library
ADMIN_CONSOLE_CHART_NAME = admin-console
ADMIN_CONSOLE_CHART_VERSION = 1.105.1
ADMIN_CONSOLE_CHART_VERSION = 1.105.2
ADMIN_CONSOLE_IMAGE_OVERRIDE =
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
EMBEDDED_OPERATOR_CHART_URL = oci://registry.replicated.com/library
Expand All @@ -14,10 +14,10 @@ OPENEBS_CHART_URL = https://openebs.github.io/charts
OPENEBS_CHART_NAME = openebs/openebs
OPENEBS_CHART_VERSION = 3.10.0
KUBECTL_VERSION = v1.29.0
K0SCTL_VERSION = v0.17.1
K0SCTL_VERSION = v0.17.3
K0S_VERSION = v1.28.4+k0s.0-ec.0
K0S_BINARY_SOURCE_OVERRIDE = "https://tf-embedded-cluster-binaries.s3.amazonaws.com/k0s-v1.28.4%2Bk0s.0-ec.0"
TROUBLESHOOT_VERSION = v0.79.0
TROUBLESHOOT_VERSION = v0.79.1
LD_FLAGS = -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sVersion=$(K0S_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/defaults.Version=$(VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sBinaryURL=$(K0S_BINARY_SOURCE_OVERRIDE) \
Expand Down
57 changes: 34 additions & 23 deletions cmd/embedded-cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

k0sv1beta1 "github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
"github.com/k0sproject/rig"
"github.com/k0sproject/rig/log"
Expand All @@ -24,6 +25,7 @@ import (

"github.com/replicatedhq/embedded-cluster/pkg/addons"
"github.com/replicatedhq/embedded-cluster/pkg/config"
"github.com/replicatedhq/embedded-cluster/pkg/customization"
"github.com/replicatedhq/embedded-cluster/pkg/defaults"
"github.com/replicatedhq/embedded-cluster/pkg/goods"
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
Expand Down Expand Up @@ -153,18 +155,6 @@ func updateConfig(c *cli.Context) error {
if err != nil {
return fmt.Errorf("unable to read cluster config: %w", err)
}
cfg.Spec.K0s.Version = k0sversion.MustParse(defaults.K0sVersion)
if c.String("overrides") != "" {
eucfg, err := parseEndUserConfig(c.String("overrides"))
if err != nil {
return fmt.Errorf("unable to process overrides file: %w", err)
}
if err := config.ApplyEmbeddedUnsupportedOverrides(
cfg, eucfg.Spec.UnsupportedOverrides.K0s,
); err != nil {
return fmt.Errorf("unable to apply overrides: %w", err)
}
}
opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
Expand All @@ -175,6 +165,10 @@ func updateConfig(c *cli.Context) error {
if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
return fmt.Errorf("unable to update helm configs: %w", err)
}
cfg.Spec.K0s.Version = k0sversion.MustParse(defaults.K0sVersion)
if err := applyUnsupportedOverrides(c, cfg); err != nil {
return fmt.Errorf("unable to apply unsupported overrides: %w", err)
}
fp, err := os.OpenFile(cfgpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("unable to create config file: %w", err)
Expand All @@ -186,6 +180,31 @@ func updateConfig(c *cli.Context) error {
return nil
}

// applyUnsupportedOverrides applies overrides to the k0s configuration. Applies first the
// overrides embedded into the binary and after the ones provided by the user (--overrides).
func applyUnsupportedOverrides(c *cli.Context, cfg *k0sv1beta1.Cluster) error {
if embcfg, err := customization.GetEmbeddedClusterConfig(); err != nil {
return fmt.Errorf("unable to get embedded cluster config: %w", err)
} else if embcfg != nil {
overrides := embcfg.Spec.UnsupportedOverrides.K0s
if err := config.ApplyEmbeddedUnsupportedOverrides(cfg, overrides); err != nil {
return fmt.Errorf("unable to apply embedded overrides: %w", err)
}
}
if c.String("overrides") == "" {
return nil
}
eucfg, err := parseEndUserConfig(c.String("overrides"))
if err != nil {
return fmt.Errorf("unable to process overrides file: %w", err)
}
overrides := eucfg.Spec.UnsupportedOverrides.K0s
if err := config.ApplyEmbeddedUnsupportedOverrides(cfg, overrides); err != nil {
return fmt.Errorf("unable to apply overrides: %w", err)
}
return nil
}

// copyUserProvidedConfig copies the user provided configuration to the config dir.
func copyUserProvidedConfig(c *cli.Context) error {
usercfg := c.String("config")
Expand Down Expand Up @@ -249,17 +268,6 @@ func ensureK0sctlConfig(c *cli.Context, useprompt bool) error {
if err != nil {
return fmt.Errorf("unable to render config: %w", err)
}
if c.String("overrides") != "" {
eucfg, err := parseEndUserConfig(c.String("overrides"))
if err != nil {
return fmt.Errorf("unable to process overrides file: %w", err)
}
if err := config.ApplyEmbeddedUnsupportedOverrides(
cfg, eucfg.Spec.UnsupportedOverrides.K0s,
); err != nil {
return fmt.Errorf("unable to apply overrides: %w", err)
}
}
opts := []addons.Option{}
if c.Bool("no-prompt") {
opts = append(opts, addons.WithoutPrompt())
Expand All @@ -270,6 +278,9 @@ func ensureK0sctlConfig(c *cli.Context, useprompt bool) error {
if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
return fmt.Errorf("unable to update helm configs: %w", err)
}
if err := applyUnsupportedOverrides(c, cfg); err != nil {
return fmt.Errorf("unable to apply unsupported overrides: %w", err)
}
fp, err := os.OpenFile(cfgpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("unable to create config file: %w", err)
Expand Down
66 changes: 66 additions & 0 deletions e2e/scripts/unsupported-overrides.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ spec:
values:
allowedUnsafeSysctls:
- net.ipv4.ip_forward
extensions:
helm:
charts:
- chartname: openebs/openebs
name: openebs
namespace: openebs
order: 1
values: |
localprovisioner:
hostpathClass:
isDefaultClass: true
ndm:
enabled: false
ndmOperator:
enabled: false
version: 3.10.0
- chartname: oci://registry.replicated.com/library/embedded-cluster-operator
name: embedded-cluster-operator
namespace: embedded-cluster
order: 2
version: 0.13.0
- chartname: oci://registry.replicated.com/library/admin-console
name: admin-console
namespace: embedded-cluster
order: 3
version: 1.105.1
values: |
isHelmManaged: false
kotsApplication: default value
minimalRBAC: false
service:
nodePort: 30000
type: NodePort
- chartname: oci://registry-1.docker.io/bitnamicharts/memcached
name: memcached
namespace: embedded-cluster
order: 4
version: 6.6.2
repositories:
- name: openebs
url: https://openebs.github.io/charts
"

embed_cluster_config() {
Expand Down Expand Up @@ -61,6 +102,27 @@ override_applied() {
cat "$K0SCTLCONFIG"
return 1
fi
if ! grep "memcached" "$K0SCTLCONFIG"; then
echo "override not applied, expected memcached helmchart not found, actual config:"
cat "$K0SCTLCONFIG"
return 1
fi
}

wait_for_memcached_pods() {
ready=$(kubectl get pods -n embedded-cluster | grep -c memcached || true)
counter=0
while [ "$ready" -lt "1" ]; do
if [ "$counter" -gt 36 ]; then
return 1
fi
sleep 5
counter=$((counter+1))
echo "Waiting for memcached pods"
ready=$(kubectl get pods -n embedded-cluster | grep -c memcached || true)
kubectl get pods -n embedded-cluster 2>&1 || true
echo "$ready"
done
}

main() {
Expand All @@ -79,6 +141,10 @@ main() {
echo "Expected override to be applied"
exit 1
fi
if ! wait_for_memcached_pods; then
echo "Failed waiting for memcached pods"
exit 1
fi
}

export EMBEDDED_CLUSTER_METRICS_BASEURL="https://staging.replicated.app"
Expand Down
17 changes: 0 additions & 17 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
k0sversion "github.com/k0sproject/version"
embeddedclusterv1beta1 "github.com/replicatedhq/embedded-cluster-operator/api/v1beta1"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
k8syaml "sigs.k8s.io/yaml"
Expand Down Expand Up @@ -52,33 +51,17 @@ func ReadConfigFile(cfgPath string) (*v1beta1.Cluster, error) {

// RenderClusterConfig renders a cluster configuration interactively.
func RenderClusterConfig(ctx context.Context, multi bool) (*v1beta1.Cluster, error) {
clusterConfig, err := customization.GetEmbeddedClusterConfig()
if err != nil {
return nil, fmt.Errorf("unable to get embedded cluster config: %w", err)
} else if clusterConfig == nil {
clusterConfig = &embeddedclusterv1beta1.Config{}
}
if multi {
cfg, err := renderMultiNodeConfig(ctx)
if err != nil {
return nil, fmt.Errorf("unable to render multi-node config: %w", err)
}
if err := ApplyEmbeddedUnsupportedOverrides(
cfg, clusterConfig.Spec.UnsupportedOverrides.K0s,
); err != nil {
return nil, fmt.Errorf("unable to apply unsupported overrides: %w", err)
}
return cfg, nil
}
cfg, err := renderSingleNodeConfig(ctx)
if err != nil {
return nil, fmt.Errorf("unable to render single-node config: %w", err)
}
if err := ApplyEmbeddedUnsupportedOverrides(
cfg, clusterConfig.Spec.UnsupportedOverrides.K0s,
); err != nil {
return nil, fmt.Errorf("unable to apply unsupported overrides: %w", err)
}
return cfg, nil
}

Expand Down

0 comments on commit 4ff8bc6

Please sign in to comment.