Reduce resource request (#218)

Signed-off-by: zhujian <jiazhu@redhat.com>
This commit is contained in:
Jian Zhu
2022-03-14 09:08:17 -04:00
committed by GitHub
parent 30c516b485
commit 4389af9344
10 changed files with 41 additions and 15 deletions
@@ -70,8 +70,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
{{ if .DetachedMode }}
volumeMounts:
- mountPath: /var/run/secrets/hub
@@ -71,8 +71,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
{{ if .DetachedMode }}
volumeMounts:
- mountPath: /var/run/secrets/hub
@@ -76,8 +76,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
volumeMounts:
- name: webhook-secret
mountPath: "/serving-cert"
@@ -75,8 +75,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
volumeMounts:
- name: webhook-secret
mountPath: "/serving-cert"
@@ -90,8 +90,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
volumes:
- name: bootstrap-secret
secret:
@@ -84,8 +84,8 @@ spec:
initialDelaySeconds: 2
resources:
requests:
cpu: 100m
memory: 128Mi
cpu: 2m
memory: 16Mi
volumes:
- name: hub-kubeconfig-secret
secret:
+13
View File
@@ -517,6 +517,19 @@ func LoadClientConfigFromSecret(secret *corev1.Secret) (*rest.Config, error) {
return clientcmd.NewDefaultClientConfig(*config, nil).ClientConfig()
}
// DetermineReplica determines the replica of deployment based on:
// - mode: if it is Hosted mode will return 1
// - node: list master nodes in the cluster and return 1 if the
// number of master nodes is equal or less than 1. Return 3 otherwise.
func DetermineReplica(ctx context.Context, kubeClient kubernetes.Interface, mode operatorapiv1.InstallMode) int32 {
// For hosted mode, there may be many cluster-manager/klusterlet running on the management cluster,
// set the replica to 1 to reduce the footprint of the management cluster.
if mode == operatorapiv1.InstallModeDetached {
return singleReplica
}
return DetermineReplicaByNodes(ctx, kubeClient)
}
// DetermineReplicaByNodes determines the replica of deployment based on:
// list master nodes in the cluster and return 1 if
// the number of master nodes is equal or less than 1. Return 3 otherwise.
+14 -1
View File
@@ -763,6 +763,7 @@ func newKubeConfigSecret(namespace, name string, kubeConfigData, certData, keyDa
func TestDeterminReplica(t *testing.T) {
cases := []struct {
name string
mode operatorapiv1.InstallMode
existingNodes []runtime.Object
expectedReplica int32
}{
@@ -776,12 +777,24 @@ func TestDeterminReplica(t *testing.T) {
existingNodes: []runtime.Object{newNode("node1"), newNode("node2"), newNode("node3")},
expectedReplica: defaultReplica,
},
{
name: "single node hosted mode",
mode: operatorapiv1.InstallModeDetached,
existingNodes: []runtime.Object{newNode("node1")},
expectedReplica: singleReplica,
},
{
name: "multiple node hosted mode",
mode: operatorapiv1.InstallModeDetached,
existingNodes: []runtime.Object{newNode("node1"), newNode("node2"), newNode("node3")},
expectedReplica: singleReplica,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
fakeKubeClient := fakekube.NewSimpleClientset(c.existingNodes...)
replica := DetermineReplicaByNodes(context.Background(), fakeKubeClient)
replica := DetermineReplica(context.Background(), fakeKubeClient, c.mode)
if replica != c.expectedReplica {
t.Errorf("Unexpected replica, actual: %d, expected: %d", replica, c.expectedReplica)
}
@@ -197,7 +197,7 @@ func (n *clusterManagerController) sync(ctx context.Context, controllerContext f
RegistrationImage: clusterManager.Spec.RegistrationImagePullSpec,
WorkImage: clusterManager.Spec.WorkImagePullSpec,
PlacementImage: clusterManager.Spec.PlacementImagePullSpec,
Replica: helpers.DetermineReplicaByNodes(ctx, n.operatorKubeClient),
Replica: helpers.DetermineReplica(ctx, n.operatorKubeClient, clusterManagerMode),
DetachedMode: clusterManager.Spec.DeployOption.Mode == operatorapiv1.InstallModeDetached,
}
// If we are deploying in the detached mode, it requires us to create webhook in a different way with the default mode.
@@ -202,7 +202,7 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto
HubKubeConfigSecret: helpers.HubKubeConfig,
ExternalServerURL: getServersFromKlusterlet(klusterlet),
OperatorNamespace: n.operatorNamespace,
Replica: helpers.DetermineReplicaByNodes(ctx, n.kubeClient),
Replica: helpers.DetermineReplica(ctx, n.kubeClient, klusterlet.Spec.DeployOption.Mode),
ExternalManagedKubeConfigSecret: helpers.ExternalManagedKubeConfig,
ExternalManagedKubeConfigRegistrationSecret: helpers.ExternalManagedKubeConfigRegistration,