Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a replicas configuration option for kustomize #11650

Closed
toyamagu-2021 opened this issue Dec 11, 2022 · 5 comments · Fixed by #11665
Closed

Add a replicas configuration option for kustomize #11650

toyamagu-2021 opened this issue Dec 11, 2022 · 5 comments · Fixed by #11665
Labels
enhancement New feature or request

Comments

@toyamagu-2021
Copy link
Member

Summary

Currently, kustomize configuration options are available only for namePrefix, nameSuffix, images, commonLabels, commonAnnotations according to argocd-doc.

I would like to see a replicas transformer to change a number of replicas kustomize-doc.

Motivation

I would like to change the number of replicas in application.yaml. Like,

apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
    # kustomize specific config
    kustomize:
      replicas:
        - name: deployment-name
          count: 5

Proposal

I think it is straightforward.

  • Kustomize already implements kustomize edit set replicas deployment-name=5.
  • And our code is ready to add the above command in
    func (k *kustomize) Build(opts *v1alpha1.ApplicationSourceKustomize, kustomizeOptions *v1alpha1.KustomizeOptions, envVars *v1alpha1.Env) ([]*unstructured.Unstructured, []Image, error) {
  • So, we can implement this feature by following the same way as fix: adding commonAnnotations #4613
@toyamagu-2021 toyamagu-2021 added the enhancement New feature or request label Dec 11, 2022
@crenshaw-dev
Copy link
Member

Sounds great to me. Want to open a PR?

@toyamagu-2021
Copy link
Member Author

@crenshaw-dev
I'll gladly do!

@maltewhiite
Copy link

maltewhiite commented Feb 19, 2023

I would love to do this with ApplicationSet as well @toyamagu-2021

ApplicationSet Example Yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
  namespace: argocd
spec:
  generators:
  - list:
      elements:
      - namespace: guestbook-qa
        url: https://kubernetes.default.svc
        values:
          frontend:
            replicas: 1
      - namespace: guestbook-e2e
        url: https://kubernetes.default.svc
        values:
          frontend:
            replicas: 2
      - namespace: guestbook-stage
        url: https://kubernetes.default.svc
        values:
          frontend:
            replicas: 3
      - namespace: guestbook-prod
        url: https://kubernetes.default.svc
        values:
          frontend:
            replicas: 5
  template:
    metadata:
      name: '{{namespace}}'
    spec:
      project: gitops
      source:
        repoURL: https://gitlab.com/kubernetes-practice/my-k8s/kia.git
        targetRevision: HEAD
        path: gitops-and-kubernetes/guestbook
        kustomize:
          replicas:
            - name: frontend
              count: '{{values.frontend.replicas}}'
      destination:
        server: '{{url}}'
        namespace: '{{namespace}}'
      syncPolicy:
        syncOptions:
        - CreateNamespace=true
        automated:
          prune: true
          selfHeal: true

@toyamagu-2021
Copy link
Member Author

@maltewhiite
Thanks for the detailed suggestions.
Yes, we can do that after #11665 is merged. I used the following manifest for the test:

applicationset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: guestbook
  namespace: argocd
spec:
  generators:
  - list:
      elements:
      - namespace: guestbook-qa
        url: https://kubernetes.default.svc
        values:
          replicas: "1"
      - namespace: guestbook-e2e
        url: https://kubernetes.default.svc
        values:
          replicas: "2"
      - namespace: guestbook-stage
        url: https://kubernetes.default.svc
        values:
          replicas: "3"
      - namespace: guestbook-prod
        url: https://kubernetes.default.svc
        values:
          replicas: "5"
  template:
    metadata:
      name: '{{namespace}}'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argocd-example-apps.git
        targetRevision: HEAD
        path: kustomize-guestbook
        kustomize:
          replicas:
            - name: kustomize-guestbook-ui
              count: '{{values.replicas}}'
      destination:
        server: '{{url}}'
        namespace: '{{namespace}}'
      syncPolicy:
        syncOptions:
        - CreateNamespace=true
        automated:
          prune: true
          selfHeal: true

Please let me know if there is any misunderstanding.

@maltewhiite
Copy link

@toyamagu-2021 Looks great! Thank you very much. Ideally my team would use auto-scalers, but this will help for sure.

crenshaw-dev added a commit that referenced this issue Mar 23, 2023
* codes

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* codegen

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* docs

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* refactor

Signed-off-by: toyamagu <toyamagu2021@gmail.com>

* fix omitenmpty

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* fix typos and add tests

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* codegen

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* chainge KustomizeReplica.counts type from int to intstr.IntOrString

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* add namespace to zero-check

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>
Signed-off-by: toyamagu <toyamagu2021@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
yyzxw pushed a commit to yyzxw/argo-cd that referenced this issue Aug 9, 2023
* codes

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* codegen

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* docs

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* refactor

Signed-off-by: toyamagu <toyamagu2021@gmail.com>

* fix omitenmpty

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* fix typos and add tests

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* codegen

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* chainge KustomizeReplica.counts type from int to intstr.IntOrString

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>

* add namespace to zero-check

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: toyamagu2021@gmail.com <toyamagu2021@gmail.com>
Signed-off-by: toyamagu <toyamagu2021@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants