Skip to content

Commit fe38969

Browse files
michi-covalenttklauser
authored andcommitted
install: Generate resource quotas from Helm chart
Use Helm chart to generate resource quotas to ensure that they don't diverge between Helm and cilium-cli. Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
1 parent 5332225 commit fe38969

File tree

1 file changed

+20
-69
lines changed

1 file changed

+20
-69
lines changed

install/install.go

+20-69
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
networkingv1 "k8s.io/api/networking/v1"
2121
rbacv1 "k8s.io/api/rbac/v1"
2222
apierrors "k8s.io/apimachinery/pkg/api/errors"
23-
"k8s.io/apimachinery/pkg/api/resource"
2423
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2524
"k8s.io/apimachinery/pkg/types"
2625

@@ -514,70 +513,14 @@ func (k *K8sInstaller) generateConfigMap() (*corev1.ConfigMap, error) {
514513
return &cm, nil
515514
}
516515

517-
func (k *K8sInstaller) deployResourceQuotas(ctx context.Context) error {
518-
k.Log("🚀 Creating Resource quotas...")
519-
520-
ciliumResourceQuota := &corev1.ResourceQuota{
521-
ObjectMeta: metav1.ObjectMeta{
522-
Name: defaults.AgentResourceQuota,
523-
},
524-
Spec: corev1.ResourceQuotaSpec{
525-
Hard: corev1.ResourceList{
526-
// 5k nodes * 2 DaemonSets (Cilium and cilium node init)
527-
corev1.ResourcePods: resource.MustParse("10k"),
528-
},
529-
ScopeSelector: &corev1.ScopeSelector{
530-
MatchExpressions: []corev1.ScopedResourceSelectorRequirement{
531-
{
532-
ScopeName: corev1.ResourceQuotaScopePriorityClass,
533-
Operator: corev1.ScopeSelectorOpIn,
534-
Values: []string{"system-node-critical"},
535-
},
536-
},
537-
},
538-
},
539-
}
540-
541-
if _, err := k.client.CreateResourceQuota(ctx, k.params.Namespace, ciliumResourceQuota, metav1.CreateOptions{}); err != nil {
542-
return err
543-
}
544-
k.pushRollbackStep(func(ctx context.Context) {
545-
if err := k.client.DeleteResourceQuota(ctx, k.params.Namespace, defaults.AgentResourceQuota, metav1.DeleteOptions{}); err != nil {
546-
k.Log("Cannot delete %s ResourceQuota: %s", defaults.AgentResourceQuota, err)
547-
}
548-
})
549-
550-
operatorResourceQuota := &corev1.ResourceQuota{
551-
ObjectMeta: metav1.ObjectMeta{
552-
Name: defaults.OperatorResourceQuota,
553-
},
554-
Spec: corev1.ResourceQuotaSpec{
555-
Hard: corev1.ResourceList{
556-
// 15 "clusterwide" Cilium Operator pods for HA
557-
corev1.ResourcePods: resource.MustParse("15"),
558-
},
559-
ScopeSelector: &corev1.ScopeSelector{
560-
MatchExpressions: []corev1.ScopedResourceSelectorRequirement{
561-
{
562-
ScopeName: corev1.ResourceQuotaScopePriorityClass,
563-
Operator: corev1.ScopeSelectorOpIn,
564-
Values: []string{"system-cluster-critical"},
565-
},
566-
},
567-
},
568-
},
569-
}
570-
571-
if _, err := k.client.CreateResourceQuota(ctx, k.params.Namespace, operatorResourceQuota, metav1.CreateOptions{}); err != nil {
572-
return err
516+
func (k *K8sInstaller) generateResourceQuotas() []*corev1.ResourceQuota {
517+
resoureceQuotasFilename := "templates/cilium-resource-quota.yaml"
518+
resourceQuotasFile, exists := k.manifests[resoureceQuotasFilename]
519+
if !exists {
520+
return nil
573521
}
574-
k.pushRollbackStep(func(ctx context.Context) {
575-
if err := k.client.DeleteResourceQuota(ctx, k.params.Namespace, defaults.OperatorResourceQuota, metav1.DeleteOptions{}); err != nil {
576-
k.Log("Cannot delete %s ResourceQuota: %s", defaults.OperatorResourceQuota, err)
577-
}
578-
})
579-
580-
return nil
522+
resourceQuotas := utils.MustUnmarshalYAMLMulti[*corev1.ResourceQuota]([]byte(resourceQuotasFile))
523+
return resourceQuotas
581524
}
582525

583526
func (k *K8sInstaller) restartUnmanagedPods(ctx context.Context) error {
@@ -729,11 +672,6 @@ func (k *K8sInstaller) Install(ctx context.Context) error {
729672
}
730673
}
731674
}
732-
case k8s.KindGKE:
733-
// TODO(aanm) automate this as well in form of helm chart
734-
if err := k.deployResourceQuotas(ctx); err != nil {
735-
return err
736-
}
737675

738676
case k8s.KindAKS:
739677
// We only made the secret-based azure installation available in >= 1.12.0
@@ -760,6 +698,19 @@ func (k *K8sInstaller) Install(ctx context.Context) error {
760698
}
761699
}
762700

701+
resourceQuotas := k.generateResourceQuotas()
702+
for _, resourceQuota := range resourceQuotas {
703+
k.Log("🚀 Creating resource quota %s...", resourceQuota.Name)
704+
if _, err := k.client.CreateResourceQuota(ctx, k.params.Namespace, resourceQuota, metav1.CreateOptions{}); err != nil {
705+
return err
706+
}
707+
k.pushRollbackStep(func(ctx context.Context) {
708+
if err := k.client.DeleteResourceQuota(ctx, k.params.Namespace, resourceQuota.Name, metav1.DeleteOptions{}); err != nil {
709+
k.Log("Cannot delete %s ResourceQuota: %s", resourceQuota.Name, err)
710+
}
711+
})
712+
}
713+
763714
k.Log("🚀 Creating Service accounts...")
764715
if _, err := k.client.CreateServiceAccount(ctx, k.params.Namespace, k.NewServiceAccount(defaults.AgentServiceAccountName), metav1.CreateOptions{}); err != nil {
765716
return err

0 commit comments

Comments
 (0)