profile
viewpoint
Zhiwei Yin zhiweiyin318 @open-cluster-management Xi'an ShaanXi China Software Engineer

zhiweiyin318/acm-submariner 0

An integration between acm and submariner

zhiweiyin318/beautifulhugo 0

Theme for the Hugo static website generator

zhiweiyin318/blog 0

Hugo blog backup

zhiweiyin318/cloud-prepare 0

Go library to prepare your cloud infrastructure via API for submariner to work on top

PullRequestReviewEvent

Pull request review commentopen-cluster-management-io/addon-framework

implement an addon using helm chart

+package main+

yes, the same agent in each examples. let me follow up to refactor the examples in another template PR.

zhiweiyin318

comment created time in 2 days

PullRequestReviewEvent

Pull request review commentopen-cluster-management-io/addon-framework

implement an addon using helm chart

+package helmaddonfactory++import (+	"embed"+	"io/fs"+	"path/filepath"+	"strings"++	"helm.sh/helm/v3/pkg/chart"+	"helm.sh/helm/v3/pkg/chart/loader"+	apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"+	apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"+	"k8s.io/apimachinery/pkg/runtime"+	"k8s.io/client-go/kubernetes/scheme"+	"k8s.io/klog/v2"+	"open-cluster-management.io/addon-framework/pkg/agent"+)++const AddonDefaultInstallNamespace = "open-cluster-management-agent-addon"++// HelmAgentAddonFactory builds an agentAddon instance from helm chart.+type HelmAgentAddonFactory struct {+	scheme            *runtime.Scheme+	chartPrefix       string+	chartFS           embed.FS+	getValuesFuncs    []GetValuesFunc+	agentAddonOptions agent.AgentAddonOptions+}++// NewAgentAddonFactoryWithHelmChartFS builds an addon agent with chart fs.+// chartPrefix is the path prefix based on the fs path.+func NewAgentAddonFactoryWithHelmChartFS(addonName string, fs embed.FS, chartPrefix string) *HelmAgentAddonFactory {+	return &HelmAgentAddonFactory{+		chartFS:     fs,+		chartPrefix: chartPrefix,+		agentAddonOptions: agent.AgentAddonOptions{+			AddonName:       addonName,+			Registration:    nil,+			InstallStrategy: nil,+		},+	}+}++// WithScheme is an optional configuration, only used when the helm chart has customized resource types.+func (f *HelmAgentAddonFactory) WithScheme(scheme *runtime.Scheme) *HelmAgentAddonFactory {+	f.scheme = scheme+	return f+}++// WithGetValuesFuncs adds a list of the getValues func.+// the values got from the big index Func will override the one from small index Func.+func (f *HelmAgentAddonFactory) WithGetValuesFuncs(getValuesFuncs []GetValuesFunc) *HelmAgentAddonFactory {+	f.getValuesFuncs = getValuesFuncs+	return f+}++// WithInstallStrategy defines the installation strategy of the manifests prescribed by Manifests(..).+func (f *HelmAgentAddonFactory) WithInstallStrategy(strategy *agent.InstallStrategy) *HelmAgentAddonFactory {+	if strategy.InstallNamespace == "" {+		strategy.InstallNamespace = AddonDefaultInstallNamespace+	}+	f.agentAddonOptions.InstallStrategy = strategy++	return f+}++// WithAgentRegistrationOption defines how agent is registered to the hub cluster.+func (f *HelmAgentAddonFactory) WithAgentRegistrationOption(option *agent.RegistrationOption) *HelmAgentAddonFactory {+	f.agentAddonOptions.Registration = option+	return f+}++// Build creates a new agentAddon.+func (f *HelmAgentAddonFactory) Build() (agent.AgentAddon, error) {+	if f.scheme == nil {+		f.scheme = runtime.NewScheme()+		_ = scheme.AddToScheme(f.scheme)+		_ = apiextensionsv1.AddToScheme(f.scheme)+		_ = apiextensionsv1beta1.AddToScheme(f.scheme)+	}++	//	chart, err := loader.Load(f.chartPath)+	userChart, err := f.loadChart()+	if err != nil {+		return nil, err+	}+	// TODO: validate chart+	agentAddon := newHelmAgentAddon(f.scheme, userChart, f.getValuesFuncs, f.agentAddonOptions)++	return agentAddon, nil+}++func (f *HelmAgentAddonFactory) loadChart() (*chart.Chart, error) {+	files, err := f.getChartFiles()+	if err != nil {+		return nil, err+	}++	klog.Info(files)++	var bfs []*loader.BufferedFile+	for _, fileName := range files {+		b, err := fs.ReadFile(f.chartFS, fileName)+		if err != nil {+			klog.Errorf("failed to read file %v. err:%v", fileName, err)+			return nil, err+		}+		klog.Info(fileName)+		bf := &loader.BufferedFile{+			Name: f.stripPrefix(fileName),+			Data: b,+		}+		bfs = append(bfs, bf)+	}++	userChart, err := loader.LoadFiles(bfs)+	if err != nil {+		klog.Errorf("failed to load chart. err:%v", err)+		return nil, err+	}+	klog.Info(userChart.ChartPath())

deleted.

zhiweiyin318

comment created time in 2 days

Pull request review commentopen-cluster-management-io/addon-framework

implement an addon using helm chart

+package helmaddonfactory++import (+	"fmt"++	"helm.sh/helm/v3/pkg/chart"+	"helm.sh/helm/v3/pkg/chartutil"+	"helm.sh/helm/v3/pkg/engine"+	"k8s.io/apimachinery/pkg/runtime"+	"k8s.io/apimachinery/pkg/runtime/serializer"+	"k8s.io/klog/v2"+	"open-cluster-management.io/addon-framework/pkg/agent"+	addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"+	clusterv1 "open-cluster-management.io/api/cluster/v1"+)++// the annotation Name of customized chart values+const annotationValuesName string = "addon.open-cluster-management.io/helmchart-values"++// the build-in values+const (+	clusterName           string = "clusterName"+	addonInstallNamespace string = "addonInstallNamespace"+	hubKubeConfigSecret   string = "hubKubeConfigSecret"+)++type Values map[string]interface{}++type GetValuesFunc func(cluster *clusterv1.ManagedCluster,+	addon *addonapiv1alpha1.ManagedClusterAddOn) (Values, error)++type HelmAgentAddon struct {+	decoder           runtime.Decoder+	chart             *chart.Chart+	getValuesFuncs    []GetValuesFunc+	agentAddonOptions agent.AgentAddonOptions+}++func newHelmAgentAddon(+	scheme *runtime.Scheme,+	chart *chart.Chart,+	getValuesFuncs []GetValuesFunc,+	agentAddonOptions agent.AgentAddonOptions) *HelmAgentAddon {+	return &HelmAgentAddon{+		decoder:           serializer.NewCodecFactory(scheme).UniversalDeserializer(),+		chart:             chart,+		getValuesFuncs:    getValuesFuncs,+		agentAddonOptions: agentAddonOptions}+}++func (a *HelmAgentAddon) Manifests(+	cluster *clusterv1.ManagedCluster,+	addon *addonapiv1alpha1.ManagedClusterAddOn) ([]runtime.Object, error) {+	var objects []runtime.Object++	values, err := a.getValues(cluster, addon)+	if err != nil {+		return objects, err+	}++	helmEngine := engine.Engine{+		Strict:   true,+		LintMode: false,+	}++	crds := a.chart.CRDObjects()+	for _, crd := range crds {+		klog.V(4).Infof("%v/n", crd.File.Data)+		object, _, err := a.decoder.Decode(crd.File.Data, nil, nil)+		if err != nil {+			return nil, err+		}+		objects = append(objects, object)+	}++	templates, err := helmEngine.Render(a.chart, values)+	if err != nil {+		return objects, err+	}+	for _, data := range templates {+		if len(data) == 0 {+			continue+		}+		klog.V(4).Infof("%v/n", data)+		object, _, err := a.decoder.Decode([]byte(data), nil, nil)+		if err != nil {+			return nil, err+		}+		objects = append(objects, object)+	}++	return objects, nil+}++func (a *HelmAgentAddon) GetAgentAddonOptions() agent.AgentAddonOptions {+	return a.agentAddonOptions+}++func (a *HelmAgentAddon) getValues(+	cluster *clusterv1.ManagedCluster,+	addon *addonapiv1alpha1.ManagedClusterAddOn) (chartutil.Values, error) {+	overrideValues := map[string]interface{}{}++	for i := 0; i < len(a.getValuesFuncs); i++ {+		if a.getValuesFuncs[i] != nil {+		}+		userValues, err := a.getValuesFuncs[i](cluster, addon)+		if err != nil {+			return overrideValues, err+		}+		overrideValues = MergeValues(overrideValues, userValues)+	}++	overrideValues = MergeValues(overrideValues, a.getBuildInValues(cluster, addon))++	values, err := chartutil.ToRenderValues(a.chart, overrideValues,+		a.releaseOptions(cluster, addon), a.capabilities(cluster, addon))+	if err != nil {+		klog.Error("failed to render helm chart with values %v. err:%v", overrideValues, err)+		return values, err+	}++	return values, nil+}++func (a *HelmAgentAddon) getBuildInValues(

done

zhiweiyin318

comment created time in 2 days

PullRequestReviewEvent

Pull request review commentopen-cluster-management-io/addon-framework

implement an addon using helm chart

+# Overview+This doc is used to introduce how to migrate Helm Chart to an Addon.++## Limitations+1. Not all of build-in Objects of Helm Chart are support in Addon. We only support below:+* Capabilities.KubeVersion+* Release.Name+* Release.Namespace++2. Not support Hooks of Helm Chart currently.++## Migration +We have an example for Helm Chart migration in [helloworld_helm](../examples/helloworld_helm).+1. Copy your helm charts into repo.

done

zhiweiyin318

comment created time in 2 days

PullRequestReviewEvent

Pull request review commentopen-cluster-management-io/addon-framework

implement an addon using helm chart

+# Overview+This doc is used to introduce how to migrate Helm Chart to an Addon.++## Limitations+1. Not all of build-in Objects of Helm Chart are support in Addon. We only support below:+* Capabilities.KubeVersion+* Release.Name+* Release.Namespace++2. Not support Hooks of Helm Chart currently.++## Migration +We have an example for Helm Chart migration in [helloworld_helm](../examples/helloworld_helm).+1. Copy your helm charts into repo.+2. Create and start helmAgentAddon instance like this:+   ```goZ

done

zhiweiyin318

comment created time in 2 days

PullRequestReviewEvent

push eventzhiweiyin318/addon-framework

Zhiwei Yin

commit sha c9ba93fac1a50e5eb3a590907184e7d2f3fa7cbb

implement an addon using helm chart Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

push time in 2 days

push eventzhiweiyin318/addon-framework

Zhiwei Yin

commit sha c41800c23a32279199d3d052070bbffcd5a73f3b

implement an addon using helm chart Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

push time in 2 days

push eventzhiweiyin318/addon-framework

Zhiwei Yin

commit sha fed6ebd0b21719e9e2e1077aa57fdee255361d44

implement an addon using helm chart Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

push time in 2 days

delete branch zhiweiyin318/cluster-lifecycle-e2e

delete branch : org-rename-2.2

delete time in 2 days

push eventstolostron/cluster-lifecycle-e2e

Zhiwei Yin

commit sha bebaa95534713579e3d4e3674bc8ee3f0068ace1

org rename Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

Zhiwei Yin

commit sha 8c43397d99ab5fec03ca332bfb4e78a84fedf6d5

Merge pull request #78 from zhiweiyin318/org-rename-2.2 org rename

view details

push time in 2 days

PR merged stolostron/cluster-lifecycle-e2e

org rename

task:https://github.com/stolostron/backlog/issues/18746 Signed-off-by: Zhiwei Yin zyin@redhat.com

+11 -17

1 comment

5 changed files

zhiweiyin318

pr closed time in 2 days

push eventzhiweiyin318/cluster-lifecycle-e2e

Zhiwei Yin

commit sha d6b1684d7c04958a45ffee249c7aed99b2d86abf

org rename Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

push time in 2 days

PR opened stolostron/cluster-lifecycle-e2e

org rename

task: https://github.com/stolostron/backlog/issues/18746 Signed-off-by: Zhiwei Yin zyin@redhat.com

+93 -106

0 comment

23 changed files

pr created time in 2 days

create barnchzhiweiyin318/cluster-lifecycle-e2e

branch : org-rename-2.4

created branch time in 2 days

PR opened stolostron/cluster-lifecycle-e2e

org rename

task https://github.com/stolostron/backlog/issues/18746 Signed-off-by: Zhiwei Yin zyin@redhat.com

+91 -93

0 comment

23 changed files

pr created time in 2 days

create barnchzhiweiyin318/cluster-lifecycle-e2e

branch : org-rename-2.3

created branch time in 2 days

PR opened stolostron/cluster-lifecycle-e2e

org rename

task:https://github.com/stolostron/backlog/issues/18746 Signed-off-by: Zhiwei Yin zyin@redhat.com

+11 -17

0 comment

5 changed files

pr created time in 2 days

create barnchzhiweiyin318/cluster-lifecycle-e2e

branch : org-rename-2.2

created branch time in 2 days

PR opened stolostron/cluster-lifecycle-e2e

org rename

task: https://github.com/stolostron/backlog/issues/18746 Signed-off-by: Zhiwei Yin zyin@redhat.com

+83 -96

0 comment

23 changed files

pr created time in 2 days

push eventzhiweiyin318/cluster-lifecycle-e2e

DangPeng Liu

commit sha 5450d08ccf33d558308bcc731a701d44cf510548

enhance quota err (#74) Signed-off-by: ldpliu <daliu@redhat.com>

view details

Zhiwei Yin

commit sha 9daa1f495d8a9694b2571b16050c1c436a4f8a30

org rename Signed-off-by: Zhiwei Yin <zyin@redhat.com>

view details

push time in 2 days

create barnchzhiweiyin318/cluster-lifecycle-e2e

branch : org-rename-main

created branch time in 2 days

pull request commentstolostron/cluster-curator-controller

trigger a new build

/lgtm

elgnay

comment created time in 2 days

pull request commentopenshift/release

org rename of stolostron work

/lgtm

elgnay

comment created time in 2 days

pull request commentstolostron/provider-credential-controller

new build

/lgtm

elgnay

comment created time in 2 days

pull request commentopen-cluster-management-io/registration-operator

add nil check for nil clients in helper

/approve /lgtm

xuezhaojun

comment created time in 2 days

more