Skip to content

Commit

Permalink
fix submariner reconcile logic
Browse files Browse the repository at this point in the history
Signed-off-by: Tom <[email protected]>
  • Loading branch information
Flying-Tom committed Aug 7, 2024
1 parent 3ae6ea6 commit 1394236
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion manifests/charts/fleet-manager/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ image:
tag: latest

logging:
level: 0
level: 5

webhook:
port: 9443
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/fleet/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,17 @@ type SubMarinerConfig struct {
// targetNamespace: submariner
// ```
//
// +optional
Chart *ChartConfig `json:"chart,omitempty"`

// ExtraArgs is the set of extra arguments for submariner, and example will be provided in the future.
//
// ```yaml
// extraArgs:
// operator:
// image:
// pullPolicy: "IfNotPresent"
// ```

// +optional
Chart *ChartConfig `json:"chart,omitempty"`
// ExtraArgs is the set of extra arguments for submariner, and example will be provided in the future.
//
// +optional
ExtraArgs apiextensionsv1.JSON `json:"extraArgs,omitempty"`
Expand Down
61 changes: 37 additions & 24 deletions pkg/fleet-manager/fleet_plugin_submariner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package fleet

import (
"context"
"errors"
"time"

"helm.sh/helm/v3/pkg/kube"
Expand Down Expand Up @@ -45,46 +46,58 @@ func (f *FleetManager) reconcileSubmarinerPlugin(ctx context.Context, fleet *fle

fleetOwnerRef := ownerReference(fleet)
var resources kube.ResourceList
var b []byte
var err error

exist_broker := false
// Install broker in the first member cluster
if len(fleetClusters) < 2 {
return nil, ctrl.Result{}, errors.New("fleetClusters number < 2")
}
for key, cluster := range fleetClusters {
if !exist_broker {
b, err = plugin.RenderSubmarinerBroker(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, submarinerCfg)
exist_broker = true
if err != nil {
return nil, ctrl.Result{}, err
}

submarinerResources, err := util.PatchResources(b)
if err != nil {
return nil, ctrl.Result{}, err
}
resources = append(resources, submarinerResources...)
}
b, err = plugin.RenderSubmarinerOperator(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
b, err := plugin.RenderSubmarinerBroker(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, submarinerCfg)
if err != nil {
return nil, ctrl.Result{}, err
}

brokerResources, err := util.PatchResources(b)
if err != nil {
return nil, ctrl.Result{}, err
}
resources = append(resources, brokerResources...)
log.V(4).Info("broker will be installed in " + key.Name)
break
}

log.V(4).Info("wait for submariner broker 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
}

// Install operator in all member clusters
for key, cluster := range fleetClusters {
b, err := plugin.RenderSubmarinerOperator(f.Manifests, fleetNN, fleetOwnerRef, plugin.KubeConfigSecretRef{
Name: key.Name,
SecretName: cluster.Secret,
SecretKey: cluster.SecretKey,
}, submarinerCfg)
if err != nil {
return nil, ctrl.Result{}, err
}

submarinerResources, err := util.PatchResources(b)
operatorResources, err := util.PatchResources(b)
if err != nil {
return nil, ctrl.Result{}, err
}
resources = append(resources, submarinerResources...)
resources = append(resources, operatorResources...)
}

log.V(4).Info("wait for submariner helm release to be reconciled")
log.V(4).Info("wait for submariner operator helm release to be reconciled")
if !f.helmReleaseReady(ctx, fleet, resources) {
// wait for HelmRelease to be ready
return nil, ctrl.Result{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ name: submariner-k8s-broker
version: 0.18.0
targetNamespace: submariner
values:
crd:
create: true
rbac:
create: true
crd:
create: true
serviceAccounts:
client:
create: true

0 comments on commit 1394236

Please sign in to comment.