Skip to content

Commit

Permalink
Install offline Helm Chart for a multi-cluster (#3897)
Browse files Browse the repository at this point in the history
* install offline Helm Chart for multi cluster

Signed-off-by: nio <nioshield@gmail.com>

* fix remotecluster current version

Signed-off-by: nio <nioshield@gmail.com>

* chore: bump ginkgo version in dev-env to v2 (#3923)

Signed-off-by: STRRL <im@strrl.dev>
Signed-off-by: nio <nioshield@gmail.com>

* Update install.sh to work on macos (#3901)

* Update install.sh to work on macos

The default bash version on MacOS does not support
reading an array directly from a variable. Instead, use
`read -a` to accomplish separating version numbers.

Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>

* chore: update changelog

Signed-off-by: STRRL <im@strrl.dev>

---------

Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>
Signed-off-by: STRRL <im@strrl.dev>
Co-authored-by: STRRL <im@strrl.dev>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Signed-off-by: nio <nioshield@gmail.com>

* update chaos-coredns version to v0.2.4 (#3947)

* update chaos-coredns version to v0.2.4

Signed-off-by: Xianglin Gao <xianglingao@tencent.com>

* update chaos-coredns version to v0.2.4

Signed-off-by: Xianglin Gao <xianglingao@tencent.com>

---------

Signed-off-by: Xianglin Gao <xianglingao@tencent.com>
Signed-off-by: nio <nioshield@gmail.com>

* Revert "update chaos-coredns version to v0.2.4" (#3967)

This reverts commit b031d88.

Signed-off-by: nio <nioshield@gmail.com>

* refactor(ui): use pnpm package manager (#3965)

* chore: init

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* test: add jest-dom types

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: add @mui/base

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: types

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* chore: update

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* chore: clear yarn usage

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* chore: update changelog

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: update storyshots

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: downgrade react-testing-library

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: @ui/app tests

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: unknown unsafe-perm

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

---------

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
Signed-off-by: nio <nioshield@gmail.com>

* upgrade dns coredns image url to ghcr.io (#3488)

* upgrade dns coredns image url to ghcr.io

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>

* add CHANGELOG

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>

* replace pingcap project with chaos-mesh

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>

* add back  docker-push-dns-server

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>

* chore: bump the version of chaos-coredns to v0.2.2

Signed-off-by: STRRL <im@strrl.dev>

* update Makefile

Signed-off-by: Cwen Yin <cwenyin0@gmail.com>

* chore: bump coredns image version to 0.2.4

Signed-off-by: STRRL <im@strrl.dev>

* test: use latest image

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: follow sonatype-lift suggestions

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* chore: update chaos-coredns to v0.2.5

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: changelog

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: typo

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: update dnsServer.image

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: remove pingcap

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: typo

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* fix: add ghcr.io registry

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* Rename ChaosDNSImage to ChaosCoreDNSImage

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>

* feat: bump chaos-coredns version to v0.2.6, and enable dnsServer.create as default

Signed-off-by: STRRL <im@strrl.dev>

* chore: update the helm chart configs

Signed-off-by: STRRL <im@strrl.dev>

* chore: make check

Signed-off-by: STRRL <im@strrl.dev>

---------

Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
Signed-off-by: STRRL <im@strrl.dev>
Signed-off-by: Cwen Yin <cwenyin0@gmail.com>
Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: STRRL <im@strrl.dev>
Co-authored-by: Cwen Yin <cwenyin0@gmail.com>
Co-authored-by: Yue Yang <g1enyy0ung@gmail.com>
Signed-off-by: nio <nioshield@gmail.com>

* fix: supplement read-only token (#3971)

Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
Signed-off-by: nio <nioshield@gmail.com>

* fix: migrate from k8s.gcr.io to registry.k8s.io (#3974)

Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
Signed-off-by: nio <nioshield@gmail.com>

* Update pkg/helm/chart.go

Co-authored-by: Zhou Zhiqiang <im@strrl.dev>
Signed-off-by: nio <nioshield@gmail.com>

---------

Signed-off-by: nio <nioshield@gmail.com>
Signed-off-by: STRRL <im@strrl.dev>
Signed-off-by: Blaine Gardner <blaine.gardner@redhat.com>
Signed-off-by: Xianglin Gao <xianglingao@tencent.com>
Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
Signed-off-by: YangKeao <yangkeao@chunibyo.icu>
Signed-off-by: Cwen Yin <cwenyin0@gmail.com>
Signed-off-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
Co-authored-by: Zhou Zhiqiang <im@strrl.dev>
Co-authored-by: Blaine Gardner <b.blaine.gardner@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
Co-authored-by: Xianglin Gao <xianglingao@tencent.com>
Co-authored-by: Yue Yang <g1enyy0ung@gmail.com>
Co-authored-by: YangKeao <yangkeao@chunibyo.icu>
Co-authored-by: Cwen Yin <cwenyin0@gmail.com>
Co-authored-by: Waleed Malik <ahmedwaleedmalik@gmail.com>
  • Loading branch information
9 people committed May 17, 2023
1 parent 5ad66d9 commit a58b954
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For more information and how-to, see [RFC: Keep A Changelog](https://github.com/
- Bump go to v1.19.3 [#3770](https://github.com/chaos-mesh/chaos-mesh/pull/3770)
- Update k8s.io dependencies to v0.26.1 [#3902](https://github.com/chaos-mesh/chaos-mesh/pull/3902)
- Update sigs.k8s.io/controller-runtime to v0.14.1 and sigs.k8s.io/controller-tools to v0.11.1 [#3902](https://github.com/chaos-mesh/chaos-mesh/pull/3902)
- Install offline Helm Chart for a multi-cluster [#3897](https://github.com/chaos-mesh/chaos-mesh/pull/3897)

### Changed

Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/remote_cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type RemoteCluster struct {
// RemoteClusterSpec defines the specification of a remote cluster
type RemoteClusterSpec struct {
Namespace string `json:"namespace"`
Version string `json:"version"`

KubeConfig RemoteClusterKubeConfig `json:"kubeConfig"`

Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/chaos-mesh.org_remoteclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ spec:
type: object
namespace:
type: string
version:
type: string
required:
- kubeConfig
- namespace
- version
type: object
status:
properties:
Expand Down
36 changes: 20 additions & 16 deletions controllers/multicluster/remotecluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
"github.com/chaos-mesh/chaos-mesh/controllers/config"
"github.com/chaos-mesh/chaos-mesh/controllers/multicluster/clusterregistry"
"github.com/chaos-mesh/chaos-mesh/pkg/helm"
)

const remoteClusterControllerFinalizer = "chaos-mesh/remotecluster-controllers"
const chaosMeshReleaseName = "chaos-mesh"
const chaosMeshReleaseVersion = "2.4.1"

type Reconciler struct {
Log logr.Logger
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil
}

err = r.ensureHelmRelease(ctx, &obj, clientConfig)
currentVersion, err := r.ensureHelmRelease(ctx, &obj, clientConfig)
if err != nil {
r.Log.Error(err, "fail to list or install remote helm release")
return ctrl.Result{Requeue: true}, nil
Expand All @@ -141,9 +141,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu

newObj.Finalizers = obj.Finalizers
setRemoteClusterCondition(&newObj, v1alpha1.RemoteClusterConditionInstalled, corev1.ConditionTrue, "")
// TODO: do auto config migration
newObj.Status.CurrentVersion = chaosMeshReleaseVersion
return r.Client.Update(ctx, &newObj)

if err = r.Client.Update(ctx, &newObj); err != nil {
return err
}
newObj.Status.CurrentVersion = currentVersion
err = r.Client.Status().Update(ctx, &newObj)
return err
})
if err != nil {
r.Log.Error(err, "fail to update finalizer", "name", obj.Name)
Expand Down Expand Up @@ -180,36 +184,36 @@ func (r *Reconciler) getHelmClient(ctx context.Context, clientConfig clientcmd.C
return helmClient, nil
}

func (r *Reconciler) ensureHelmRelease(ctx context.Context, obj *v1alpha1.RemoteCluster, clientConfig clientcmd.ClientConfig) error {
func (r *Reconciler) ensureHelmRelease(ctx context.Context, obj *v1alpha1.RemoteCluster, clientConfig clientcmd.ClientConfig) (string, error) {
helmClient, err := r.getHelmClient(ctx, clientConfig)
if err != nil {
return err
return "", err
}

_, err = helmClient.GetRelease(obj.Spec.Namespace, chaosMeshReleaseName)
release, err := helmClient.GetRelease(obj.Spec.Namespace, chaosMeshReleaseName)
if err != nil {
if errors.Is(err, driver.ErrReleaseNotFound) {
chart, err := helm.FetchChaosMeshChart(ctx, chaosMeshReleaseVersion)
chart, err := helm.FetchChaosMeshChart(ctx, obj.Spec.Version, config.ControllerCfg.LocalHelmChartPath)
if err != nil {
return err
return "", err
}

values := make(map[string]interface{})
if obj.Spec.ConfigOverride != nil {
err = json.Unmarshal(obj.Spec.ConfigOverride, &values)
if err != nil {
return err
return "", err
}
}
_, err = helmClient.UpgradeOrInstall(obj.Spec.Namespace, chaosMeshReleaseName, chart, values)
release, err = helmClient.UpgradeOrInstall(obj.Spec.Namespace, chaosMeshReleaseName, chart, values)
if err != nil {
return err
return "", err
}
} else {
return err
return "", err
}
}
return nil

return release.Chart.AppVersion(), nil
}

func (r *Reconciler) uninstallHelmRelease(ctx context.Context, obj *v1alpha1.RemoteCluster, clientConfig clientcmd.ClientConfig) error {
Expand Down
3 changes: 3 additions & 0 deletions helm/chaos-mesh/crds/chaos-mesh.org_remoteclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ spec:
type: object
namespace:
type: string
version:
type: string
required:
- kubeConfig
- namespace
- version
type: object
status:
properties:
Expand Down
13 changes: 13 additions & 0 deletions helm/chaos-mesh/templates/controller-manager-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ spec:
- name: POD_FAILURE_PAUSE_IMAGE
value: {{ .Values.controllerManager.podChaos.podFailure.pauseImage }}
{{- end }}
{{- if .Values.controllerManager.localHelmChart.enabled }}
- name: LOCAL_HELM_CHART_PATH
value: /data/helm
{{- end }}
- name: ENABLE_LEADER_ELECTION
value: {{ .Values.controllerManager.leaderElection.enabled | quote }}
- name: LEADER_ELECT_LEASE_DURATION
Expand All @@ -160,6 +164,11 @@ spec:
mountPath: /etc/chaosd/cert
readOnly: true
{{- end }}
{{- if .Values.controllerManager.localHelmChart.enabled }}
- name: chaos-local-helm-chart
mountPath: /data/helm
readOnly: true
{{- end }}
ports:
- name: webhook
containerPort: {{ .Values.controllerManager.env.WEBHOOK_PORT }}
Expand Down Expand Up @@ -202,6 +211,10 @@ spec:
secret:
secretName: {{ template "chaos-mesh.chaosd-client.certs" . }}
{{- end }}
{{- if .Values.controllerManager.localHelmChart.enabled }}
- name: chaos-local-helm-chart
{{ toYaml .Values.controllerManager.localHelmChart.volume | indent 10 }}
{{- end }}
{{- with .Values.controllerManager.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
Expand Down
7 changes: 7 additions & 0 deletions helm/chaos-mesh/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ controllerManager:
retryPeriod: 2s
# chaosdSecurityMode is enabled for mTLS connection between chaos-controller-manager and chaosd
chaosdSecurityMode: true
# multi cluster install offline helm chart path
localHelmChart:
enabled: false
volume:
hostPath:
path: /data/helm
type: DirectoryOrCreate

chaosDaemon:
# image would be constructed by <registry>/<repository>:<tag>
Expand Down
3 changes: 3 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5322,9 +5322,12 @@ spec:
type: object
namespace:
type: string
version:
type: string
required:
- kubeConfig
- namespace
- version
type: object
status:
properties:
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type ChaosControllerConfig struct {

EnabledControllers []string `envconfig:"ENABLED_CONTROLLERS" default:"*"`
EnabledWebhooks []string `envconfig:"ENABLED_WEBHOOKS" default:"*"`

LocalHelmChartPath string `envconfig:"LOCAL_HELM_CHART_PATH" default:""`
}

// EnvironChaosController returns the settings from the environment.
Expand Down
32 changes: 27 additions & 5 deletions pkg/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,43 @@ import (

const ChaosMeshHelmRepo = "https://charts.chaos-mesh.org"

func FetchChaosMeshChart(ctx context.Context, version string) (*chart.Chart, error) {
tgzPath, err := DownloadChaosMeshChartTgz(ctx, version)
if err != nil {
return nil, err
func FetchChaosMeshChart(ctx context.Context, version, local string) (*chart.Chart, error) {
var (
tgzPath string
err error
)
if local != "" {
if tgzPath, err = GetChaosMeshChartTgzPath(ctx, version, local); err != nil {
return nil, err
}
} else {
if tgzPath, err = DownloadChaosMeshChartTgz(ctx, version); err != nil {
return nil, err
}
}

requestedChart, err := loader.Load(tgzPath)
if err != nil {
return nil, errors.Wrapf(err, "load helm chart from %s", tgzPath)
}
return requestedChart, nil
}

func GetChaosMeshChartTgzPath(ctx context.Context, version, local string) (string, error) {
fileName := fmt.Sprintf("chaos-mesh-%s.tgz", version)
tgzPath := fmt.Sprintf("%s/%s", os.TempDir(), fileName)
if local != "" {
tgzPath = fmt.Sprintf("%s/%s", local, fileName)
}

if _, err := os.Stat(tgzPath); err != nil {
return "", err
}
return tgzPath, nil
}

func DownloadChaosMeshChartTgz(ctx context.Context, version string) (string, error) {
// TODO: use this context

url := fmt.Sprintf("%s/chaos-mesh-%s.tgz", ChaosMeshHelmRepo, version)
response, err := http.Get(url)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExampleDownloadChaosMeshChartTgz() {
}

func ExampleFetchChaosMeshChart() {
chart, err := FetchChaosMeshChart(context.Background(), "2.2.0")
chart, err := FetchChaosMeshChart(context.Background(), "2.2.0", "")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit a58b954

Please sign in to comment.