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 7668 #778

Merged
merged 5 commits into from Nov 4, 2022
Merged

Conversation

Patryk-Stefanski
Copy link
Contributor

@Patryk-Stefanski Patryk-Stefanski commented Aug 22, 2022

What

THREESCALE-7668
Addition of new application CR, that supports :

  • Create
  • Update (Name, application plan, description)
  • Delete
  • Suspend

Verification

  1. As this PR with new functionality hasnt been merged yet, check out this branch of porta client locally.

  2. Check out this 3scale-operator branch locally and add the following line of code to go.mod. (This will use the local version of the porta client setup in step1)

replace github.com/3scale/3scale-porta-go-client v0.6.0 =>  <LOCATION_OF_LOCAL_PORTA_CLIENT_REPO>
  1. Run the following commands to install the 3scale operator
go mod vendor 
go mod tidy 
make install
export NAMESPACE=3scale-test
oc new-project $NAMESPACE
make download
make run
  1. For the operator to create routes we need to mock the s3 credentials secret, run the following command.
kubectl apply -f - <<EOF
---
kind: Secret
apiVersion: v1
metadata: 
  name: s3-credentials
  namespace: 3scale-test
data: 
  AWS_ACCESS_KEY_ID: UkVQTEFDRV9NRQ==
  AWS_BUCKET: UkVQTEFDRV9NRQ==
  AWS_REGION: UkVQTEFDRV9NRQ==
  AWS_SECRET_ACCESS_KEY: UkVQTEFDRV9NRQ==
type: Opaque
EOF
  1. Deploy the API manager CR and specify your cluster wildcardDomain.
kubectl apply -f - <<EOF
---
apiVersion: apps.3scale.net/v1alpha1
kind: APIManager
metadata: 
  name: apimanager-sample
  namespace: 3scale-test
spec: 
  system: 
    fileStorage: 
      simpleStorageService: 
        configurationSecretRef: 
          name: s3-credentials
  wildcardDomain: apps.pstefans.****.s1.devshift.org
EOF
  1. Create the required secrets for Accounts, products and backends. You can find the admin token in system-seed secret and the admin URL under routes in the 3scale-test namespace.
kubectl apply -f - <<EOF
---
apiVersion: v1
kind: Secret
metadata:
  name: mytenant
type: Opaque
stringData:
  adminURL: <ADMIN_URL>
  token: "<ADMIN_ACCESS_TOKEN>"
EOF

kubectl apply -f - <<EOF
---
apiVersion: v1
kind: Secret
metadata:
  name: myusername01
stringData:
  password: "123456"
EOF
  1. Create the developerAccount, DeveloperUser, product and backend required for the application CR.
kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: DeveloperUser
metadata:
  name: developeruser01
  namespace: 3scale-test
spec:
  developerAccountRef:
    name: developeraccount01
  email: myusername01@example.com
  passwordCredentialsRef:
    name: myusername01
  providerAccountRef:
    name: mytenant
  role: admin
  username: myusername01
EOF

kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: DeveloperAccount
metadata:
  name: developeraccount01
  namespace: 3scale-test
spec:
  orgName: pstefans3
  providerAccountRef:
    name: mytenant
EOF


kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Backend
metadata:
  name: backend1-cr
  namespace: 3scale-test
spec:
  mappingRules:
    - httpMethod: GET
      increment: 1
      last: true
      metricMethodRef: hits
      pattern: /
  name: backend1
  privateBaseURL: 'https://api.example.com'
  systemName: backend1
EOF

kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Product
metadata:
  name: product1-cr
  namespace: 3scale-test
spec:
  applicationPlans:
    plan01:
      name: "My Plan 01"
      limits:
        - period: month
          value: 300
          metricMethodRef:
            systemName: hits
            backend: backend1
    plan02:
      name: "My Plan 02"
      limits:
        - period: month
          value: 300
          metricMethodRef:
            systemName: hits
            backend: backend1
  name: product1
  backendUsages:
    backend1:
      path: /
EOF

9.Create an Invalid Application CR , status should give out about invalid account and product CR names.

kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Application
metadata:
  name: example
  namespace: 3scale-test
spec:
  accountCR: 
    name: developeraccount02
  applicationPlanName: plan03
  productCR: 
    name: product2-cr
  name: testApp
  description: further testing
EOF
  1. Update Application Resource , it should give out about the plan being used not belonging to the product.
kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Application
metadata:
  name: example
  namespace: 3scale-test
spec:
  accountCR: 
    name: developeraccount01
  applicationPlanName: plan03
  productCR: 
    name: product1-cr
  name: testApp
  description: further testing
EOF
  1. Update Application resource once again, this time the status should report ready: true with no error message. Check in 3scale UI that app has been created.
kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Application
metadata:
  name: example
  namespace: 3scale-test
spec:
  accountCR: 
    name: developeraccount01
  applicationPlanName: plan01
  productCR: 
    name: product1-cr
  name: testApp
  description: further testing
EOF
  1. Update the application one last time to check that updating the name , description , plan and suspending works.Check that the application update is reflected in 3scale UI and that the app has gone into the suspended state.
kubectl apply -f - <<EOF
---
apiVersion: capabilities.3scale.net/v1beta1
kind: Application
metadata:
  name: example
  namespace: 3scale-test
spec:
  accountCR: 
    name: developeraccount01
  applicationPlanName: plan02
  productCR: 
    name: product1-cr
  name: testApp12 
  description: further testing12
  suspend: true
EOF

apis/capabilities/v1beta1/application_types.go Outdated Show resolved Hide resolved
apis/capabilities/v1beta1/application_types.go Outdated Show resolved Hide resolved
config/samples/capabilities_v1beta1_application.yaml Outdated Show resolved Hide resolved
pkg/controller/helper/application_entity.go Show resolved Hide resolved
controllers/capabilities/application_controller.go Outdated Show resolved Hide resolved
controllers/capabilities/application_controller.go Outdated Show resolved Hide resolved
controllers/capabilities/application_controller.go Outdated Show resolved Hide resolved
controllers/capabilities/application_controller.go Outdated Show resolved Hide resolved
@Patryk-Stefanski
Copy link
Contributor Author

@austincunningham would you mind addressing the remaining comments? Not sure I can do much without a cluster.

FYI some tests are failing cause we are using porta-client v0.6 which doesnt have the new changes, think we might need a new tag for porta @eguzki

@eguzki
Copy link
Member

eguzki commented Sep 15, 2022

/retest

@austincunningham austincunningham removed the work in progress Don't merge, there's still work to do. label Oct 5, 2022
@austincunningham
Copy link
Contributor

/ok-to-test

@austincunningham austincunningham added the work in progress Don't merge, there's still work to do. label Oct 6, 2022
@austincunningham austincunningham removed the work in progress Don't merge, there's still work to do. label Oct 7, 2022
@eguzki
Copy link
Member

eguzki commented Oct 21, 2022

verification steps working 💪

Copy link
Member

@eguzki eguzki left a comment

Choose a reason for hiding this comment

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

Looking good!

I left some comments.

Awesome work testing the app controller logic.

I see there is some doc for the Application CRD reference. It would be very nice to have some higher level as user guide. Also useful for downstream doc. In https://github.com/3scale/3scale-operator/blob/master/doc/operator-application-capabilities.md,

  • add Application CRD to the index, with link to the ref doc.
  • add few examples
  • Some "howto" user guide, very similar to the verification steps, so the end user can easily follow steps to deploy an application.

I realized that we missed this for the ProxyConfigPromote CRD

@eguzki
Copy link
Member

eguzki commented Oct 25, 2022

heads up, after merging #785, this PR would need to be rebased and some (hopefully few and small) changes should be applied.

Patryk-Stefanski and others added 3 commits October 25, 2022 15:52
Create, Read and Update basics working

Fixing nil pointer and adding suspend/resume functionality

Adding external resources check and changing application status

Addressing comments

Add documentation

remove json unmarshal and check for invalid status

move the account and product get to applicationReconciler

remove generated test-suite file

update to 3scale-porta-go-client v0.7.0

make bundle

add basic unit tests for create and delete application CR

test for suspension/live and change plan ID

update the status on the developer account not found
@codeclimate
Copy link

codeclimate bot commented Nov 2, 2022

Code Climate has analyzed commit 715c23d and detected 40 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 11
Duplication 9
Style 20

View more on Code Climate.

@austincunningham
Copy link
Contributor

/test test-e2e

1 similar comment
@austincunningham
Copy link
Contributor

/test test-e2e

@eguzki
Copy link
Member

eguzki commented Nov 4, 2022

Awesome work @austincunningham 🎖️

@eguzki
Copy link
Member

eguzki commented Nov 4, 2022

I spotted small nitpicks, but we can work with them in coming PR's

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.

None yet

4 participants