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-11633 fix application controller nil pointer #1065

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MStokluska
Copy link
Contributor

@MStokluska MStokluska commented Jan 29, 2025

Jira: https://issues.redhat.com/browse/THREESCALE-11633

Verification:

Install 3scale:

  • run make cluster/prepare/local
  • run:
export NAMESPACE=3scale-test

cat << EOF | oc create -f -
kind: Secret
apiVersion: v1
metadata:
  name: s3-credentials
  namespace: $NAMESPACE
data:
  AWS_ACCESS_KEY_ID: c29tZXRoaW5nCg==
  AWS_BUCKET: c29tZXRoaW5nCg==
  AWS_REGION: dXMtd2VzdC0xCg==
  AWS_SECRET_ACCESS_KEY: c29tZXRoaW5nCg==
type: Opaque
EOF

DOMAIN=$(oc get routes console -n openshift-console -o json | jq -r '.status.ingress[0].routerCanonicalHostname' | sed 's/router-default.//')
cat << EOF | oc create -f -
kind: APIManager
apiVersion: apps.3scale.net/v1alpha1
metadata:
  name: 3scale
  namespace: $NAMESPACE
spec:
  externalComponents:
    backend:
      redis: true
    system:
      database: true
      redis: true
  wildcardDomain: $DOMAIN
  system:
    fileStorage:
      simpleStorageService:
        configurationSecretRef:
          name: s3-credentials
EOF
  • run make run
  • let 3scale install
  • run:
cat << EOF | oc create -f -
---
apiVersion: v1
kind: Secret
metadata:
  name: developeruserpassword4
stringData:
  password: developeruserpassword4
---
apiVersion: capabilities.3scale.net/v1beta1
kind: DeveloperAccount
metadata:
  name: developeraccount04
spec:
  orgName: Ecorp
---
apiVersion: capabilities.3scale.net/v1beta1
kind: DeveloperUser
metadata:
  name: developeruser04
spec:
  username: myusername04
  email: [email protected]
  role: admin
  passwordCredentialsRef:
    name: developeruserpassword4
  developerAccountRef:
    name: developeraccount04
EOF
  • run:
cat << EOF | oc create -f -
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Product
metadata:
  name: testproduct
spec:
  description: Custom resources test product
  applicationPlans:
    default:
      name: default
  metrics:
    hits:
      description: Number of API hits
      friendlyName: Hits
      unit: hit
  name: testapp
  systemName: testapp
EOF
  • run:
cat << EOF | oc create -f -
---
kind: Application
apiVersion: capabilities.3scale.net/v1beta1
metadata:
  name: testapplication
spec:
  accountCR:
    name: developeraccount04
  applicationPlanName: default
  description: Custom resources test application
  name: testapplication
  productCR:
    name: testproduct
---
kind: Application
apiVersion: capabilities.3scale.net/v1beta1
metadata:
  name: testapplication2
spec:
  accountCR:
    name: developeraccount04
  applicationPlanName: default
  description: Custom resources test application
  name: testapplication2
  productCR:
    name: testproduct
EOF

Test 1:

  • let all create successfully
  • confirm that application CRs now reference the account CR as ownerRef
  • delete testapplication2
  • confirm testapplication2 removed from 3scale and from cluster
  • delete the dev account CR and confirm dev account is gone from 3scale along with application
  • confirm the application, dev user and dev account are deleted from cluster.

Test 2:

  • re-create the resources again
  • wait for all to create successfully
  • delete application testapplication2
  • scale down the operator
  • take copy of dev user and dev account (spec + metadata)
  • delete dev user + dev ACC CRs (remember to clear the finalizers)
  • confirm application CR has been marked for deletion
  • re-create dev user and dev ACC (just spec and metadata that you have copied over)
  • run the operator
  • expectation is that 1) operator won't crash 2) dev acc and user CRs will be synced 3) application CR will be removed from cluster.

Test 3:

  • re-create all resources and let them provision successfully
  • take a backup of application CRs including metadata
  • scale down operator
  • remove application CRs from cluster
  • add application CRs back to cluster without the status but with all the metadata
  • scale up operator
  • application should be synced with existing application in 3scale with the same ID instead of being re-created

@MStokluska MStokluska requested a review from a team as a code owner January 29, 2025 12:48
@@ -268,6 +268,11 @@ func (r *ApplicationReconciler) removeApplicationFrom3scale(application *capabil
return nil
}

if account.Status.ID == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this throw a nil pointer if account.Status is nil?

Suggested change
if account.Status.ID == nil {
if account.Status != nil && account.Status.ID == nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, following the verification steps you will get to try it out as we are adding the account CRs back on to the cluster but without the status.

@MStokluska
Copy link
Contributor Author

"Failed to pull image "image-registry.openshift-image-registry.svc"

Restarting e2e

/test test-e2e

@MStokluska
Copy link
Contributor Author

/test test-e2e

@MStokluska MStokluska changed the title THREESCALE-11633 fix application controller nil pointer [WIP] THREESCALE-11633 fix application controller nil pointer Jan 30, 2025
@MStokluska
Copy link
Contributor Author

Going to extend this with parent/child logic between applications and dev acc

@MStokluska MStokluska changed the title [WIP] THREESCALE-11633 fix application controller nil pointer THREESCALE-11633 fix application controller nil pointer Feb 5, 2025
@MStokluska
Copy link
Contributor Author

/test test-e2e

@austincunningham
Copy link
Contributor

Verification

Test 1

  • Installed the operator
  • created the developer Account and User
  • created the Product
  • created the 2 applications
  • confirmed that all create successfully
  • Checked the owner ref in the application CR's
metadata:
  namespace: 3scale-test
  ownerReferences:
    - apiVersion: capabilities.3scale.net/v1beta1
      blockOwnerDeletion: true
      controller: true
      kind: DeveloperAccount
      name: developeraccount04
      uid: ed6f1f80-0ebb-490a-8b5f-e4a808ebe59f

image

  • Deleted testapplication2 & confirm testapplication2 removed from 3scale and from cluster

image

 oc get applications
NAME              AGE
testapplication   12m
  • deleted the developer account and confirmed that the account and the application are removed from the cluster & 3scale
oc get developeraccounts
No resources found in 3scale-test namespace.
oc get applications
No resources found in 3scale-test namespace.

image
image

Test 2

  • re-created the resources again
  • waited for all to create successfully
  • Scaled down the operator
  • Deleted application testapplication2 CR and confirmed its marked for deletion as the deletionTimestamp is set
apiVersion: capabilities.3scale.net/v1beta1
kind: Application
metadata:
  annotations:
    applicationID: '17'
  deletionTimestamp: '2025-02-06T10:13:41Z'
  • copied the spec and metadata from developerUser developerAccount
  • deleted the developerUser developerAccount
  • All applications CR's marked with deletionTimestamp
  • Recreated developerUser developerAccount with the copied spec and metadata
  • restarted the operator
  • operator didn't crash and all applications have been removed.

Test 3

  • re-created all resources and let them provision successfully
  • taken a backup of application CRs including metadata
  • scale down operator
  • deleted the applications and removed the finalizers
  • recreated the applications with the backed up metadata
  • restarted the operator
  • applications are not recreated or duplicated
    image

/lgtm
/approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants