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

THREESCALE-8754 Enhance replica reconciliation #784

Merged
merged 5 commits into from
Sep 30, 2022

Conversation

eguzki
Copy link
Member

@eguzki eguzki commented Sep 28, 2022

what

Implements https://issues.redhat.com/browse/THREESCALE-8754

  • Remove adding replica values to the CR
  • Reconciliation (implemented by the mutator) only added when the replicas field is set

Components

  • backend listener
  • backend worker
  • backend cron
  • apicast staging
  • apicast production
  • system app
  • system sidekiq
  • zync
  • zync que

Verification steps

run env

make install
make run

Deploy APIManager CR with no replica definition

k apply -f -<<EOF
---
apiVersion: v1
kind: Secret
metadata:
  creationTimestamp: null
  name: aws-auth
stringData:
  AWS_ACCESS_KEY_ID: somekey
  AWS_SECRET_ACCESS_KEY: something
  AWS_BUCKET: example.com
  AWS_REGION: us-east-1
type: Opaque
---
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
  name: apimanager1
spec:
  wildcardDomain: example.com
  resourceRequirementsEnabled: false
  system:
    fileStorage:
      simpleStorageService:
        configurationSecretRef:
          name: aws-auth
EOF

Check that the APIManager CR does not have replicas in the CR

k get apimanager.apps.3scale.net/apimanager1 -o yaml
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata:
  annotations:
    apps.3scale.net/apimanager-threescale-version: "2.13"
    apps.3scale.net/threescale-operator-version: 0.10.0
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps.3scale.net/v1alpha1","kind":"APIManager","metadata":{"annotations":{},"name":"apimanager1","namespace":"3scale-operator-test"},"spec":{"resourceRequirementsEnabled":false,"system":{"fileStorage":{"simpleStorageService":{"configurationSecretRef":{"name":"aws-auth"}}}},"wildcardDomain":"3scale-operator-test.apps.dev-eng-ocp4-operator.dev.3sca.net"}}
  creationTimestamp: "2022-09-29T09:34:19Z"
  generation: 2
  name: apimanager1
  namespace: 3scale-operator-test
  resourceVersion: "9968928"
  uid: 14854404-5511-43fc-bfbb-181155e50aa3
spec:
  apicast:
    managementAPI: status
    openSSLVerify: false
    productionSpec: {}
    registryURL: http://apicast-staging:8090/policies
    responseCodes: true
    stagingSpec: {}
  appLabel: 3scale-api-management
  backend:
    cronSpec: {}
    listenerSpec: {}
    workerSpec: {}
  imageStreamTagImportInsecure: false
  resourceRequirementsEnabled: false
  system:
    appSpec: {}
    fileStorage:
      simpleStorageService:
        configurationSecretRef:
          name: aws-auth
    sidekiqSpec: {}
    sphinxSpec: {}
  tenantName: 3scale
  wildcardDomain: 3scale-operator-test.apps.dev-eng-ocp4-operator.dev.3sca.net
  zync:
    appSpec: {}
    queSpec: {}

Wait for deployment to be available

oc wait --for=condition=available apimanager/apimanager1 --timeout=-1s
apimanager.apps.3scale.net/apimanager1 condition met

Let's pick one subcomponent (it should be the same for any one where you can specify replicas): apicast-staging

Check the number of pods is 1 for the apicast staging

k get dc apicast-staging
NAME              REVISION   DESIRED   CURRENT   TRIGGERED BY
apicast-staging   1          1         1         config,image(amp-apicast:2.13)

Scale to 3 via the deploymentconfig

k scale --replicas=3 deploymentconfig apicast-staging
Warning: extensions/v1beta1 Scale is deprecated in v1.2+, unavailable in v1.16+
deploymentconfig.apps.openshift.io/apicast-staging scaled

Check the deployment has 3 replicas

k get pods -l deploymentConfig=apicast-staging
NAME                      READY   STATUS    RESTARTS   AGE
apicast-staging-1-7ds4r   1/1     Running   0          14m
apicast-staging-1-l8l95   1/1     Running   0          106s
apicast-staging-1-lfstj   1/1     Running   0          106s

Add replicas to the APIManager CR with a value of 2

k patch apimanager apimanager1 --type merge --patch '{"spec":{"apicast": {"stagingSpec": {"replicas": 2}}}}'
apimanager.apps.3scale.net/apimanager1 patched

Check the deployment has 2 replicas

k get pods -l deploymentConfig=apicast-staging
NAME                      READY   STATUS    RESTARTS   AGE
apicast-staging-1-7ds4r   1/1     Running   0          16m
apicast-staging-1-lfstj   1/1     Running   0          4m21s

As replicas are set explicitly in the CR, changes in the deployment will be reverted back. If we try to scale to 3 via the deployment

k scale --replicas=3 deploymentconfig apicast-staging

The number of replicas will still be 2

k get pods -l deploymentConfig=apicast-staging
NAME                      READY   STATUS    RESTARTS   AGE
apicast-staging-1-7ds4r   1/1     Running   0          17m
apicast-staging-1-lfstj   1/1     Running   0          5m32s

@openshift-ci
Copy link

openshift-ci bot commented Sep 28, 2022

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@MStokluska
Copy link
Contributor

Looks good to me and logic makes sense, going to run through verification later on this week.

@codeclimate
Copy link

codeclimate bot commented Sep 28, 2022

Code Climate has analyzed commit 9714119 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 3

View more on Code Climate.

@eguzki eguzki changed the title Enhance replica reconciliation THREESCALE-8754 Enhance replica reconciliation Sep 29, 2022
@eguzki eguzki marked this pull request as ready for review September 29, 2022 09:52
Copy link
Contributor

@MStokluska MStokluska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, code changes make sense and the functionality works as expected. Good idea @eguzki

@eguzki eguzki merged commit ca185cb into master Sep 30, 2022
@eguzki eguzki deleted the enhance-replica-reconciliation branch September 30, 2022 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants