Skip to content

Commit

Permalink
move member agent hub manager leader election to member cluster (Azur…
Browse files Browse the repository at this point in the history
…e#261)

Co-authored-by: Ryan Zhang <[email protected]>
  • Loading branch information
ryanzhang-oss and Ryan Zhang authored Sep 6, 2022
1 parent 44551d3 commit 5c86e71
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
5 changes: 3 additions & 2 deletions cmd/memberagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ func main() {
}

memberConfig := ctrl.GetConfigOrDie()

// we place the leader election lease on the member cluster to avoid adding load to the hub
hubOpts := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: *hubMetricsAddr,
Port: 8443,
HealthProbeBindAddress: *hubProbeAddr,
LeaderElection: *enableLeaderElection,
LeaderElectionNamespace: mcNamespace, // This requires we have access to resource "leases" in API group "coordination.k8s.io" under namespace $mcHubNamespace
LeaderElectionNamespace: *leaderElectionNamespace,
LeaderElectionConfig: memberConfig,
LeaderElectionID: "136224848560.hub.fleet.azure.com",
Namespace: mcNamespace,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/membercluster/membercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (r *Reconciler) syncRole(ctx context.Context, mc *fleetv1alpha1.MemberClust
Namespace: namespaceName,
OwnerReferences: []metav1.OwnerReference{*toOwnerReference(mc)},
},
Rules: []rbacv1.PolicyRule{utils.FleetRule, utils.EventRule, utils.FleetNetworkRule, utils.LeaseRule, utils.WorkRule},
Rules: []rbacv1.PolicyRule{utils.FleetRule, utils.EventRule, utils.FleetNetworkRule, utils.WorkRule},
}

// Creates role if not found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestSyncRole(t *testing.T) {
Name: "fleet-role-mc1",
Namespace: namespace1,
},
Rules: []rbacv1.PolicyRule{utils.FleetRule, utils.EventRule, utils.FleetNetworkRule, utils.LeaseRule, utils.WorkRule},
Rules: []rbacv1.PolicyRule{utils.FleetRule, utils.EventRule, utils.FleetNetworkRule, utils.WorkRule},
}
return nil
},
Expand Down
13 changes: 4 additions & 9 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ const (
)

const (
// LabelFleetObj is a label key indicate the resource is created by the fleet
// LabelFleetObj is a label key indicate the resource is created by the fleet.
LabelFleetObj = "kubernetes.azure.com/managed-by"
LabelFleetObjValue = "fleet"

// LabelWorkPlacementName is used to indicate which placement created the work.
// This label aims to enable different work objects to be managed by different placement.
LabelWorkPlacementName = "work.fleet.azure.com/placement-name"

// PlacementFinalizer is used to make sure that we handle gc of placement resources
// PlacementFinalizer is used to make sure that we handle gc of placement resources.
PlacementFinalizer = "work.fleet.azure.com/placement-protection"
)
const (
// NetworkingGroupName is the group name of the fleet networking
// NetworkingGroupName is the group name of the fleet networking.
NetworkingGroupName = "networking.fleet.azure.com"
)

Expand All @@ -82,14 +82,9 @@ var (
APIGroups: []string{NetworkingGroupName},
Resources: []string{"*"},
}
// LeaseRule Leases permissions are required for leader election of hub controller manager in member cluster.
LeaseRule = rbacv1.PolicyRule{
Verbs: []string{"create", "get", "list", "update"},
APIGroups: []string{"coordination.k8s.io"},
Resources: []string{"leases"},
}
)

// Those are the GVR/GVK of the fleet related resources.
var (
ClusterResourcePlacementGVR = schema.GroupVersionResource{
Group: fleetv1alpha1.GroupVersion.Group,
Expand Down

0 comments on commit 5c86e71

Please sign in to comment.