Skip to content

Commit

Permalink
complete fleet plugin install flagger
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <lizhencheng6@huawei.com>
  • Loading branch information
LiZhenCheng9527 committed Nov 20, 2023
1 parent 0da3b7b commit 6b385f2
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 6 deletions.
71 changes: 71 additions & 0 deletions docs/content/en/references/fleet_v1alpha1_types.html
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ <h3 id="fleet.kurator.dev/v1alpha1.ChartConfig">ChartConfig
(<em>Appears on:</em>
<a href="#fleet.kurator.dev/v1alpha1.BackupConfig">BackupConfig</a>,
<a href="#fleet.kurator.dev/v1alpha1.DistributedStorageConfig">DistributedStorageConfig</a>,
<a href="#fleet.kurator.dev/v1alpha1.FlaggerConfig">FlaggerConfig</a>,
<a href="#fleet.kurator.dev/v1alpha1.GrafanaConfig">GrafanaConfig</a>,
<a href="#fleet.kurator.dev/v1alpha1.KyvernoConfig">KyvernoConfig</a>,
<a href="#fleet.kurator.dev/v1alpha1.PrometheusConfig">PrometheusConfig</a>,
Expand Down Expand Up @@ -551,6 +552,63 @@ <h3 id="fleet.kurator.dev/v1alpha1.Endpoints">Endpoints
(<em>Appears on:</em>
<a href="#fleet.kurator.dev/v1alpha1.FleetStatus">FleetStatus</a>)
</p>
<h3 id="fleet.kurator.dev/v1alpha1.FlaggerConfig">FlaggerConfig
</h3>
<p>
(<em>Appears on:</em>
<a href="#fleet.kurator.dev/v1alpha1.PluginConfig">PluginConfig</a>)
</p>
<div class="md-typeset__scrollwrap">
<div class="md-typeset__table td-content">
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>chart</code><br>
<em>
<a href="#fleet.kurator.dev/v1alpha1.ChartConfig">
ChartConfig
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>Chart defines the helm chart config of the flagger.
default values is</p>
<p>chart:
repository: oci://ghcr.io/fluxcd/charts
name: flagger
version: 1.x</p>
</td>
</tr>
<tr>
<td>
<code>extraArgs</code><br>
<em>
<a href="https://pkg.go.dev/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1?tab=doc#JSON">
Kubernetes /apiextensions/v1.JSON
</a>
</em>
</td>
<td>
<em>(Optional)</em>
<p>ExtraArgs is the set of extra arguments for flagger chart.</p>
<p>For Example, using following configuration to change replica count.
extraArgs:
flagger:
replicaCount: 2</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 id="fleet.kurator.dev/v1alpha1.FleetPhase">FleetPhase
(<code>string</code> alias)</h3>
<p>
Expand Down Expand Up @@ -1182,6 +1240,19 @@ <h3 id="fleet.kurator.dev/v1alpha1.PluginConfig">PluginConfig
<p>DistributedStorage define the configuration for the distributed storage(Implemented with Rook)</p>
</td>
</tr>
<tr>
<td>
<code>flagger</code><br>
<em>
<a href="#fleet.kurator.dev/v1alpha1.FlaggerConfig">
FlaggerConfig
</a>
</em>
</td>
<td>
<p>Flagger defines the configuretion for the kurator CD engine.</p>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
29 changes: 29 additions & 0 deletions manifests/charts/fleet-manager/crds/fleet.kurator.dev_fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,35 @@ spec:
required:
- storage
type: object
flagger:
description: Flagger defines the configuretion for the kurator
CD engine.
properties:
chart:
description: "Chart defines the helm chart config of the flagger.
default values is \n chart: repository: oci://ghcr.io/fluxcd/charts
name: flagger version: 1.x"
properties:
name:
description: Name defines the name of the chart. Default
value depends on the kind of the component.
type: string
repository:
description: Repository defines the repository of chart.
Default value depends on the kind of the component.
type: string
version:
description: Version defines the version of the chart.
Default value depends on the kind of the component.
type: string
type: object
extraArgs:
description: "ExtraArgs is the set of extra arguments for
flagger chart. \n For Example, using following configuration
to change replica count. extraArgs: flagger: replicaCount:
2"
x-kubernetes-preserve-unknown-fields: true
type: object
grafana:
description: Grafana defines the configuration for the grafana
installation and observation.
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/fleet/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,21 +480,21 @@ type StorageDeviceSelection struct {
}

type FlaggerConfig struct {
// Chart defines the helm chart config of the grafana.
// Chart defines the helm chart config of the flagger.
// default values is
//
// chart:
// repository: oci://registry-1.docker.io/bitnamicharts
// name: grafana
// version: 8.2.33
// repository: oci://ghcr.io/fluxcd/charts
// name: flagger
// version: 1.x
//
// +optional
Chart *ChartConfig `json:"chart,omitempty"`
// ExtraArgs is the set of extra arguments for Grafana chart.
// ExtraArgs is the set of extra arguments for flagger chart.
//
// For Example, using following configuration to change replica count.
// extraArgs:
// grafana:
// flagger:
// replicaCount: 2
//
// +optional
Expand Down
1 change: 1 addition & 0 deletions pkg/fleet-manager/fleet_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (f *FleetManager) reconcilePlugins(ctx context.Context, fleet *fleetapi.Fle
f.reconcileKyvernoPlugin,
f.reconcileBackupPlugin,
f.reconcileDistributedStoragePlugin,
f.reconcileFlaggerPlugin,
}

resultsChannel := make(chan reconcileResult, len(funcs))
Expand Down
80 changes: 80 additions & 0 deletions pkg/fleet-manager/fleet_plugin_flagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright Kurator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fleet

import (
"context"
"time"

"helm.sh/helm/v3/pkg/kube"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"

fleetapi "kurator.dev/kurator/pkg/apis/fleet/v1alpha1"
"kurator.dev/kurator/pkg/fleet-manager/plugin"
"kurator.dev/kurator/pkg/infra/util"
)

// reconcileFlaggerPlugin reconciles the Flagger plugin.
// The fleetClusters parameter is currently unused, but is included to match the function signature of other functions in reconcilePlugins.
func (f *FleetManager) reconcileFlaggerPlugin(ctx context.Context, fleet *fleetapi.Fleet, fleetClusters map[ClusterKey]*fleetCluster) (kube.ResourceList, ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)

flaggerCfg := fleet.Spec.Plugin.Flagger

if flaggerCfg == nil {
// reconcilePluginResources will delete all resources if plugin is nil
return nil, ctrl.Result{}, nil
}

fleetNN := types.NamespacedName{
Namespace: fleet.Namespace,
Name: fleet.Name,
}

fleetOwnerRef := ownerReference(fleet)
var resources kube.ResourceList

for key, cluster := range fleetClusters {
b, err := plugin.RendeFlagger(f.Manifests, fleetNN, fleetOwnerRef, plugin.FleetCluster{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, flaggerCfg)
if err != nil {
return nil, ctrl.Result{}, err
}

// apply flagger helm resources
flaggerResources, err := util.PatchResources(b)
if err != nil {
return nil, ctrl.Result{}, err
}
resources = append(resources, flaggerResources...)
}

log.V(4).Info("wait for flagger helm release to be reconciled")
if !f.helmReleaseReady(ctx, fleet, resources) {
// wait for HelmRelease to be ready
return nil, ctrl.Result{
// HelmRelease check interval is 1m, so we set 30s here
RequeueAfter: 30 * time.Second,
}, nil
}

return resources, ctrl.Result{}, nil
}
8 changes: 8 additions & 0 deletions pkg/fleet-manager/manifests/plugins/flagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: oci
repo: oci://ghcr.io/fluxcd/charts
name: flagger
version: 1.x # update Flagger to the latest minor version
targetNamespace: flagger-system
values:
nodeSelector:
kubernetes.io/os: linux
32 changes: 32 additions & 0 deletions pkg/fleet-manager/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
BackupPluginName = "backup"
StorageOperatorPluginName = "storage-operator"
ClusterStoragePluginName = "cluster-storage"
FlaggerPluginName = "flagger"

ThanosComponentName = "thanos"
PrometheusComponentName = "prometheus"
Expand All @@ -47,6 +48,7 @@ const (
VeleroComponentName = "velero"
RookOperatorComponentName = "rook"
RookClusterComponentName = "rook-ceph"
FlaggerComponentName = "flagger"

OCIReposiotryPrefix = "oci://"
)
Expand Down Expand Up @@ -473,6 +475,36 @@ func buildStorageClusterValue(distributedStorageCfg fleetv1a1.DistributedStorage
return customValues
}

func RendeFlagger(
fsys fs.FS,
fleetNN types.NamespacedName,
fleetRef *metav1.OwnerReference,
cluster FleetCluster,
flaggerConfig *fleetv1a1.FlaggerConfig,
) ([]byte, error) {
// get and merge the chart config
c, err := getFleetPluginChart(fsys, FlaggerComponentName)
if err != nil {
return nil, err
}
mergeChartConfig(c, flaggerConfig.Chart)

values, err := toMap(flaggerConfig.ExtraArgs)
if err != nil {
return nil, err
}

return renderFleetPlugin(fsys, FleetPluginConfig{
Name: FlaggerPluginName,
Component: FlaggerComponentName,
Fleet: fleetNN,
Cluster: &cluster,
OwnerReference: fleetRef,
Chart: *c,
Values: values,
})
}

func mergeChartConfig(origin *ChartConfig, target *fleetv1a1.ChartConfig) {
if target == nil {
return
Expand Down

0 comments on commit 6b385f2

Please sign in to comment.