Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Xieql <xieqianglong@huawei.com>
  • Loading branch information
Xieql committed Nov 28, 2023
1 parent 5de1517 commit ff9026f
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 39 deletions.
1 change: 0 additions & 1 deletion pkg/fleet-manager/fleet_plugin_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (f *FleetManager) reconcileBackupPlugin(ctx context.Context, fleet *v1alpha
for key, cluster := range fleetClusters {
// generate Velero helm config for each fleet cluster
b, err := plugin.RenderVelero(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, veleroCfg, newSecret.Name)
Expand Down
6 changes: 2 additions & 4 deletions pkg/fleet-manager/fleet_plugin_distributedstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ func (f *FleetManager) reconcileDistributedStoragePlugin(ctx context.Context, fl
var resources kube.ResourceList

// First install rook-operator for the specified multicluster.
for key, cluster := range fleetClusters {
for _, cluster := range fleetClusters {
b, err := plugin.RendeStorageOperator(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, distributedStorageCfg)
Expand All @@ -74,9 +73,8 @@ func (f *FleetManager) reconcileDistributedStoragePlugin(ctx context.Context, fl

// After Rook operator are created, starts to install rook-ceph
if distributedStorageCfg.Storage != nil {
for key, cluster := range fleetClusters {
for _, cluster := range fleetClusters {
b, err := plugin.RenderClusterStorage(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, distributedStorageCfg)
Expand Down
6 changes: 2 additions & 4 deletions pkg/fleet-manager/fleet_plugin_kyverno.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ func (f *FleetManager) reconcileKyvernoPlugin(ctx context.Context, fleet *fleetv

fleetOwnerRef := ownerReference(fleet)
var resources kube.ResourceList
for key, cluster := range fleetClusters {
for _, cluster := range fleetClusters {
b, err := plugin.RenderKyverno(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, fleet.Spec.Plugin.Policy.Kyverno)
Expand All @@ -76,10 +75,9 @@ func (f *FleetManager) reconcileKyvernoPlugin(ctx context.Context, fleet *fleetv

// After CRDs are created, start to install pod security policy
if kyvernoCfg.PodSecurity != nil {
for key, cluster := range fleetClusters {
for _, cluster := range fleetClusters {
// generate policies for pod security admission
b, err := plugin.RenderKyvernoPolicy(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, kyvernoCfg)
Expand Down
3 changes: 1 addition & 2 deletions pkg/fleet-manager/fleet_plugin_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ func (f *FleetManager) reconcileMetricPlugin(ctx context.Context, fleet *fleetap
return nil, ctrl.Result{}, fmt.Errorf("failed to reconcile objstore secret for cluster %s: %w", c.Name, err)
}

b, err := plugin.RenderPrometheus(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: c.Name,
b, err := plugin.RenderPrometheus(f.Manifests, fleetNN, fleetOwnerRef, c.Name, plugin.KubeConfigSecretRef{
SecretName: fleetCluster.Secret,
SecretKey: fleetCluster.SecretKey,
}, metricCfg)
Expand Down
4 changes: 2 additions & 2 deletions pkg/fleet-manager/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func RenderThanos(fsys fs.FS, fleetNN types.NamespacedName, fleetRef *metav1.Own
return renderFleetPlugin(fsys, thanosCfg)
}

func RenderPrometheus(fsys fs.FS, fleetName types.NamespacedName, fleetRef *metav1.OwnerReference, cluster KubeConfigSecretRef, metricCfg *fleetv1a1.MetricConfig) ([]byte, error) {
func RenderPrometheus(fsys fs.FS, fleetName types.NamespacedName, fleetRef *metav1.OwnerReference, clusterName string, cluster KubeConfigSecretRef, metricCfg *fleetv1a1.MetricConfig) ([]byte, error) {
promChart, err := getFleetPluginChart(fsys, PrometheusComponentName)
if err != nil {
return nil, err
Expand All @@ -197,7 +197,7 @@ func RenderPrometheus(fsys fs.FS, fleetName types.NamespacedName, fleetRef *meta
values = transform.MergeMaps(values, map[string]interface{}{
"prometheus": map[string]interface{}{
"externalLabels": map[string]interface{}{
"cluster": cluster.Name,
"cluster": clusterName,
},
"thanos": map[string]interface{}{
"objectStorageConfig": map[string]interface{}{
Expand Down
8 changes: 1 addition & 7 deletions pkg/fleet-manager/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestRenderKyvernoPolicy(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderKyvernoPolicy(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.in)
Expand Down Expand Up @@ -99,7 +98,6 @@ func TestRenderKyverno(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderKyverno(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.in)
Expand Down Expand Up @@ -270,8 +268,7 @@ func TestRenderPrometheus(t *testing.T) {

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderPrometheus(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
got, err := RenderPrometheus(manifestFS, tc.fleet, tc.ref, "cluster1", KubeConfigSecretRef{
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.in)
Expand Down Expand Up @@ -383,7 +380,6 @@ func TestRenderVelero(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderVelero(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.in, tc.newSecretName)
Expand Down Expand Up @@ -438,7 +434,6 @@ func TestRenderStorageOperator(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RendeStorageOperator(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.config)
Expand Down Expand Up @@ -528,7 +523,6 @@ func TestRenderClusterStorage(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := RenderClusterStorage(manifestFS, tc.fleet, tc.ref, KubeConfigSecretRef{
Name: "cluster1",
SecretName: "cluster1",
SecretKey: "kubeconfig.yaml",
}, tc.config)
Expand Down
19 changes: 0 additions & 19 deletions pkg/fleet-manager/plugin/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,7 @@ type FleetPluginConfig struct {
Values map[string]interface{}
}

func (plugin FleetPluginConfig) ResourceName() string {
if plugin.Cluster != nil {
return plugin.Component + "-" + plugin.Cluster.Name
}

return plugin.Component
}

func (plugin FleetPluginConfig) StorageNamespace() string {
// StorageNamespace is the namespace where the plugin stores its data
// It's same as the target namespace for cluster scoped plugins
if plugin.Cluster != nil {
return plugin.Chart.TargetNamespace
}

return plugin.Fleet.Namespace
}

type KubeConfigSecretRef struct {
Name string
SecretName string
SecretKey string
}
Expand Down

0 comments on commit ff9026f

Please sign in to comment.