Skip to content

Commit

Permalink
feat: add the leader election (#230)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Zhang <zhangryan@microsoft.com>
  • Loading branch information
ryanzhang-oss and Ryan Zhang committed Aug 10, 2022
1 parent 57a4d98 commit c8dcdd5
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 687 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ uninstall-helm-charts: clean-testing-kind-clusters-resources
.PHONY: clean-testing-kind-clusters-resources
clean-testing-kind-clusters-resources:
kind export kubeconfig --name $(HUB_KIND_CLUSTER_NAME)
kubectl delete ns fleet-kind-member-testing --ignore-not-found
kubectl delete ns fleet-member-kind-member-testing --ignore-not-found
kubectl delete memberclusters.fleet.azure.com kind-$(MEMBER_KIND_CLUSTER_NAME) --ignore-not-found

kind export kubeconfig --name $(MEMBER_KIND_CLUSTER_NAME)
kubectl delete ns fleet-kind-member-testing --ignore-not-found
kubectl delete ns fleet-member-kind-member-testing --ignore-not-found

.PHONY: clean-e2e-tests
clean-e2e-tests: ## Remove
Expand Down
413 changes: 245 additions & 168 deletions charts/hub-agent/templates/crds/multicluster.x-k8s.io_works.yaml

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions charts/hub-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ spec:
- --leader-elect=true
- --enable-webhook={{ .Values.enableWebhook }}
- --v={{ .Values.logVerbosity }}
- -add_dir_header
ports:
- name: http
containerPort: 80
- name: metrics
containerPort: 8080
protocol: TCP
- name: healthz
containerPort: 8081
protocol: TCP
livenessProbe:
httpGet:
path: /healthz
port: healthz
readinessProbe:
httpGet:
path: /readyz
port: healthz
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion charts/hub-agent/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: hub-agent-role-binding
name: {{ include "hub-agent.fullname" . }}-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,94 +1,124 @@
# Copyright 2021 The Kubernetes 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.
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: appliedworks.multicluster.x-k8s.io
spec:
group: multicluster.x-k8s.io
names:
categories:
- fleet
kind: AppliedWork
listKind: AppliedWorkList
plural: appliedworks
singular: appliedwork
scope: Cluster
versions:
- name: v1alpha1
served: true
storage: true
subresources:
status: {}
"schema":
"openAPIV3Schema":
description: AppliedWork represents an applied work on managed cluster that is placed on a managed cluster. An appliedwork links to a work on a hub recording resources deployed in the managed cluster. When the agent is removed from managed cluster, cluster-admin on managed cluster can delete appliedmanifestwork to remove resources deployed by the agent. The name of the appliedwork must be the same as {manifestwork name} The namespace of the appliedwork should be the same as the resource applied on the managed cluster.
type: object
required:
- spec
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec represents the desired configuration of AppliedManifestWork.
type: object
required:
- workName
- workNamespace
properties:
workName:
description: WorkName represents the name of the related work on the hub.
type: string
workNamespace:
description: WorkNamespace represents the namespace of the related work on the hub.
type: string
status:
description: Status represents the current status of AppliedManifestWork.
type: object
properties:
appliedResources:
description: AppliedResources represents a list of resources defined within the manifestwork that are applied. Only resources with valid GroupVersionResource, namespace, and name are suitable. An item in this slice is deleted when there is no mapped manifest in manifestwork.Spec or by finalizer. The resource relating to the item will also be removed from managed cluster. The deleted resource may still be present until the finalizers for that resource are finished. However, the resource will not be undeleted, so it can be removed from this list and eventual consistency is preserved.
type: array
items:
description: AppliedResourceMeta represents the group, version, resource, name and namespace of a resource. Since these resources have been created, they must have valid group, version, resource, namespace, and name.
type: object
properties:
group:
description: Group is the group of the resource.
type: string
kind:
description: Kind is the kind of the resource.
type: string
name:
description: Name is the name of the resource
type: string
namespace:
description: Namespace is the namespace of the resource, the resource is cluster scoped if the value is empty
type: string
ordinal:
description: Ordinal represents an index in manifests list, so the condition can still be linked to a manifest even thougth manifest cannot be parsed successfully.
type: integer
resource:
description: Resource is the resource type of the resource
type: string
uid:
description: UID is set on successful deletion of the Kubernetes resource by controller. The resource might be still visible on the managed cluster after this field is set. It is not directly settable by a client.
type: string
version:
description: Version is the version of the resource.
type: string
- name: v1alpha1
schema:
openAPIV3Schema:
description: AppliedWork represents an applied work on managed cluster that
is placed on a managed cluster. An appliedwork links to a work on a hub
recording resources deployed in the managed cluster. When the agent is removed
from managed cluster, cluster-admin on managed cluster can delete appliedmanifestwork
to remove resources deployed by the agent. The name of the appliedwork must
be the same as {manifestwork name} The namespace of the appliedwork should
be the same as the resource applied on the managed cluster.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec represents the desired configuration of AppliedManifestWork.
properties:
workName:
description: WorkName represents the name of the related work on the
hub.
type: string
workNamespace:
description: WorkNamespace represents the namespace of the related
work on the hub.
type: string
required:
- workName
- workNamespace
type: object
status:
description: Status represents the current status of AppliedManifestWork.
properties:
appliedResources:
description: AppliedResources represents a list of resources defined
within the manifestwork that are applied. Only resources with valid
GroupVersionResource, namespace, and name are suitable. An item
in this slice is deleted when there is no mapped manifest in manifestwork.Spec
or by finalizer. The resource relating to the item will also be
removed from managed cluster. The deleted resource may still be
present until the finalizers for that resource are finished. However,
the resource will not be undeleted, so it can be removed from this
list and eventual consistency is preserved.
items:
description: AppliedResourceMeta represents the group, version,
resource, name and namespace of a resource. Since these resources
have been created, they must have valid group, version, resource,
namespace, and name.
properties:
group:
description: Group is the group of the resource.
type: string
kind:
description: Kind is the kind of the resource.
type: string
name:
description: Name is the name of the resource
type: string
namespace:
description: Namespace is the namespace of the resource, the
resource is cluster scoped if the value is empty
type: string
ordinal:
description: Ordinal represents an index in manifests list,
so the condition can still be linked to a manifest even thougth
manifest cannot be parsed successfully.
type: integer
resource:
description: Resource is the resource type of the resource
type: string
uid:
description: UID is set on successful deletion of the Kubernetes
resource by controller. The resource might be still visible
on the managed cluster after this field is set. It is not
directly settable by a client.
type: string
version:
description: Version is the version of the resource.
type: string
required:
- ordinal
type: object
type: array
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading

0 comments on commit c8dcdd5

Please sign in to comment.