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

Refactor deployment.go code #365

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bshephar
Copy link
Collaborator

@bshephar bshephar commented Sep 19, 2024

This change does some refactoring of the deployment.go code to avoid overuse of string literals and replace with consts. Along with moving excessive code from the main Deployment function into dedicated functions that are easier to test and read.

The second commit adds a dedicated deployment_test.go file. This will allow us to perform more comprehensive testing of the individual functions without depending on the limited number of scenarios we're running with envtest.

@openshift-ci openshift-ci bot requested review from lewisdenny and viroel September 19, 2024 00:26
Copy link
Contributor

openshift-ci bot commented Sep 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bshephar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bshephar
Copy link
Collaborator Author

/test horizon-operator-build-deploy-kuttl

@bshephar bshephar marked this pull request as draft January 9, 2025 00:19
@bshephar
Copy link
Collaborator Author

bshephar commented Jan 9, 2025

Seems to be an issue with the VolumeMounts:

    case.go:380: resource Horizon:horizon-kuttl-tests/horizon: .status.readyCount: key is missing from map
    logger.go:42: 12:27:14 | tls-deployment | skipping kubernetes event logging

Failure is related to the missing combined-ca-bundle mount:

❯ curl -s "https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/pr-logs/pull/openstack-k8s-operators_horizon-operator/365/pull-ci-openstack-k8s-operators-horizon-operator-main-horizon-operator-build-deploy-kuttl/1876224488794755072/artifacts/horizon-operator-build-deploy-kuttl/openstack-k8s-operators-gather/artifacts/must-gather/quay-io-openstack-k8s-operators-openstack-must-gather-sha256-b14292f8b5bb013eb06a54a9a50a2d892f6dd255901a7842f65567beb8cd090d/namespaces/horizon-kuttl-tests/crs/horizons.horizon.openstack.org/horizon.yaml" | yq '.status.conditions[0]'
lastTransitionTime: "2025-01-06T12:27:14Z"
message: 'TLSInput is missing: combined-ca-bundle'
reason: Requested
severity: Info
status: "False"
type: Ready

@bshephar bshephar force-pushed the refactor-cleanup branch 2 times, most recently from 3d38314 to 5c88425 Compare February 6, 2025 22:32
@bshephar bshephar marked this pull request as ready for review February 6, 2025 23:38
@openshift-ci openshift-ci bot requested review from abays and dprince February 6, 2025 23:38
@bshephar bshephar marked this pull request as draft February 6, 2025 23:38
@bshephar
Copy link
Collaborator Author

bshephar commented Feb 6, 2025

/test horizon-operator-build-deploy-kuttl

@bshephar
Copy link
Collaborator Author

bshephar commented Feb 7, 2025

/test horizon-operator-build-deploy-kuttl

@bshephar
Copy link
Collaborator Author

bshephar commented Feb 7, 2025

/test functional

@bshephar
Copy link
Collaborator Author

bshephar commented Feb 7, 2025

Hmm, still complains that the secret is missing:

  Warning  FailedMount     112s                   kubelet            MountVolume.SetUp failed for volume "combined-ca-bundle" : secret "combined-ca-bundle" not found
  Warning  FailedMount     112s                   kubelet            MountVolume.SetUp failed for volume "horizon-tls-certs" : secret "cert-horizon-svc" not found
❯ curl -s "https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/pr-logs/pull/openstack-k8s-operators_horizon-operator/365/pull-ci-openstack-k8s-operators-horizon-operator-main-horizon-operator-build-deploy-kuttl/1887657005825396736/artifacts/horizon-operator-build-deploy-kuttl/openstack-k8s-operators-gather/artifacts/must-gather/quay-io-openstack-k8s-operators-openstack-must-gather-sha256-125ca476d114b0e95cbbb8df0485c867fef29386646a6631e95e7a18e1eeb85c/namespaces/horizon-kuttl-tests/crs/horizons.horizon.openstack.org/horizon.yaml" | yq ".status.conditions[0]"
lastTransitionTime: "2025-02-07T01:26:12Z"
message: 'TLSInput is missing: combined-ca-bundle'
reason: Requested
severity: Info
status: "False"
type: Ready

I was hoping we might be able to catch this with the functional test I added. But I might be misunderstanding the mechanism responsible for creating the ca-bundle.

It should be created by:
https://github.com/openstack-k8s-operators/horizon-operator/blob/main/tests/kuttl/tests/tls-deployment/00-tls_ca_bundle.yaml

So, I'm not too sure why this change results in it being missing.

❯ curl -s "https://storage.googleapis.com/test-platform-results/pr-logs/pull/openstack-k8s-operators_horizon-operator/365/pull-ci-openstack-k8s-operators-horizon-operator-main-horizon-operator-build-deploy-kuttl/1887657005825396736/build-log.txt" | grep "combined-ca-bundle
created"
    logger.go:42: 01:23:09 | tls-deployment/0-tls_ca_bundle | Secret:horizon-kuttl-tests/combined-ca-bundle created

It's possible the must-gather is being collected too late I guess. Probably easier to find this issue in e2e tests.

@stuggi
Copy link
Contributor

stuggi commented Feb 7, 2025

But it seems not to be only a tls issue, also the basic test is not successful, its just not stopping and continue also the tls test

    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | + RETURN_CODE=0
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | ++ oc get -n horizon-kuttl-tests horizon horizon -o 'jsonpath={.status.endpoint}'
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | + PUBLIC_URL=http://horizon.horizon-kuttl-tests.svc
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | ++ oc -n horizon-kuttl-tests exec -it deployment/horizon -- curl --silent --output /dev/stderr --head --write-out '%{http_code}' 'http://horizon.horizon-kuttl-tests.svc/dashboard/auth/login/?next=/dashboard/' -k
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | Unable to use a TTY - input is not a terminal or the right kind of file
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | command terminated with exit code 7
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + STATUSCODE=000
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + [[ -n 000 ]]
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + test 000 -ne 200
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + RETURN_CODE=1
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + echo 'http://horizon.horizon-kuttl-tests.svc status code expected is 200 but was 000'
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | http://horizon.horizon-kuttl-tests.svc status code expected is 200 but was 000
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + exit 1
    logger.go:42: 01:23:09 | basic-deployment/1-deploy-horizon | test step failed 1-deploy-horizon
    case.go:378: failed in step 1-deploy-horizon
    case.go:380: --- Horizon:horizon-kuttl-tests/horizon
        +++ Horizon:horizon-kuttl-tests/horizon
        @@ -1,14 +1,31 @@
         apiVersion: horizon.openstack.org/v1beta1
         kind: Horizon
         metadata:
        +  annotations:
        +    kubectl.kubernetes.io/last-applied-configuration: |
        +      {"apiVersion":"horizon.openstack.org/v1beta1","kind":"Horizon","metadata":{"annotations":{},"name":"horizon","namespace":"horizon-kuttl-tests"},"spec":{"customServiceConfig":"DEBUG = True\nLOGGING['handlers']['console']['level'] = 'DEBUG'\n","replicas":1,"secret":"osp-secret"}}
        +  finalizers:
        +  - openstack.org/horizon
        +  managedFields: '[... elided field over 10 lines long ...]'
           name: horizon
           namespace: horizon-kuttl-tests
         spec:
        +  containerImage: quay.io/podified-antelope-centos9/openstack-horizon@sha256:7b8817f2ee32bd77d6ec38524cfbc12c060966bb5c48c0ba04d6d21e401ee2c5
           customServiceConfig: |
             DEBUG = True
             LOGGING['handlers']['console']['level'] = 'DEBUG'
        +  extraMounts: []
        +  memcachedInstance: memcached
        +  override: {}
        +  preserveJobs: false
           replicas: 1
        +  resources: {}
           secret: osp-secret
        +  tls: {}
         status:
        -  readyCount: 1
        +  conditions: '[... elided field over 10 lines long ...]'
        +  endpoint: http://horizon.horizon-kuttl-tests.svc
        +  hash:
        +    input: nbfh678h9ch587h69h687h74h675h67bh57bh59h67h55ch695h96h95h5c5h655h5c5h59bhb5h54chcbhf5hc4h9ch587h8dh67fhcbh559h68dq
        +  observedGeneration: 1
         
        
    case.go:380: resource Horizon:horizon-kuttl-tests/horizon: .status.readyCount: key is missing from map
    case.go:380: command "RETURN_CODE=0\\n PUBLIC_URL=$(oc get -n $NAMESPACE horizon horizon -..." failed, exit status 1

Bot kuttl tests fail

--- FAIL: kuttl (364.73s)
    --- FAIL: kuttl/harness (0.00s)
        --- FAIL: kuttl/harness/basic-deployment (181.42s)
        --- FAIL: kuttl/harness/tls-deployment (183.16s)

@bshephar bshephar force-pushed the refactor-cleanup branch 2 times, most recently from 8b021a6 to 6c84979 Compare February 10, 2025 11:57
@bshephar
Copy link
Collaborator Author

/test horizon-operator-build-deploy-kuttl

@bshephar
Copy link
Collaborator Author

But it seems not to be only a tls issue, also the basic test is not successful, its just not stopping and continue also the tls test

    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | + RETURN_CODE=0
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | ++ oc get -n horizon-kuttl-tests horizon horizon -o 'jsonpath={.status.endpoint}'
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | + PUBLIC_URL=http://horizon.horizon-kuttl-tests.svc
    logger.go:42: 01:23:07 | basic-deployment/1-deploy-horizon | ++ oc -n horizon-kuttl-tests exec -it deployment/horizon -- curl --silent --output /dev/stderr --head --write-out '%{http_code}' 'http://horizon.horizon-kuttl-tests.svc/dashboard/auth/login/?next=/dashboard/' -k
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | Unable to use a TTY - input is not a terminal or the right kind of file
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | command terminated with exit code 7
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + STATUSCODE=000
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + [[ -n 000 ]]
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + test 000 -ne 200
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + RETURN_CODE=1
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + echo 'http://horizon.horizon-kuttl-tests.svc status code expected is 200 but was 000'
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | http://horizon.horizon-kuttl-tests.svc status code expected is 200 but was 000
    logger.go:42: 01:23:08 | basic-deployment/1-deploy-horizon | + exit 1
    logger.go:42: 01:23:09 | basic-deployment/1-deploy-horizon | test step failed 1-deploy-horizon
    case.go:378: failed in step 1-deploy-horizon
    case.go:380: --- Horizon:horizon-kuttl-tests/horizon
        +++ Horizon:horizon-kuttl-tests/horizon
        @@ -1,14 +1,31 @@
         apiVersion: horizon.openstack.org/v1beta1
         kind: Horizon
         metadata:
        +  annotations:
        +    kubectl.kubernetes.io/last-applied-configuration: |
        +      {"apiVersion":"horizon.openstack.org/v1beta1","kind":"Horizon","metadata":{"annotations":{},"name":"horizon","namespace":"horizon-kuttl-tests"},"spec":{"customServiceConfig":"DEBUG = True\nLOGGING['handlers']['console']['level'] = 'DEBUG'\n","replicas":1,"secret":"osp-secret"}}
        +  finalizers:
        +  - openstack.org/horizon
        +  managedFields: '[... elided field over 10 lines long ...]'
           name: horizon
           namespace: horizon-kuttl-tests
         spec:
        +  containerImage: quay.io/podified-antelope-centos9/openstack-horizon@sha256:7b8817f2ee32bd77d6ec38524cfbc12c060966bb5c48c0ba04d6d21e401ee2c5
           customServiceConfig: |
             DEBUG = True
             LOGGING['handlers']['console']['level'] = 'DEBUG'
        +  extraMounts: []
        +  memcachedInstance: memcached
        +  override: {}
        +  preserveJobs: false
           replicas: 1
        +  resources: {}
           secret: osp-secret
        +  tls: {}
         status:
        -  readyCount: 1
        +  conditions: '[... elided field over 10 lines long ...]'
        +  endpoint: http://horizon.horizon-kuttl-tests.svc
        +  hash:
        +    input: nbfh678h9ch587h69h687h74h675h67bh57bh59h67h55ch695h96h95h5c5h655h5c5h59bhb5h54chcbhf5hc4h9ch587h8dh67fhcbh559h68dq
        +  observedGeneration: 1
         
        
    case.go:380: resource Horizon:horizon-kuttl-tests/horizon: .status.readyCount: key is missing from map
    case.go:380: command "RETURN_CODE=0\\n PUBLIC_URL=$(oc get -n $NAMESPACE horizon horizon -..." failed, exit status 1

Bot kuttl tests fail

--- FAIL: kuttl (364.73s)
    --- FAIL: kuttl/harness (0.00s)
        --- FAIL: kuttl/harness/basic-deployment (181.42s)
        --- FAIL: kuttl/harness/tls-deployment (183.16s)

Yeah, there's something else going on. Maybe it's the probes, I should look closer at those probes:

  Warning  Unhealthy       4m18s                kubelet            Startup probe failed: Get "https://10.128.0.128:443/dashboard/auth/login/?next=/dashboard/": dial tcp 10.128.0.128:443: connect: connection refused
  Warning  Unhealthy       98s (x18 over 4m6s)  kubelet            Readiness probe failed: HTTP probe failed with statuscode: 404

@bshephar
Copy link
Collaborator Author

/test horizon-operator-build-deploy-kuttl

@bshephar
Copy link
Collaborator Author

/test horizon-operator-build-deploy-kuttl
/test functional

@bshephar
Copy link
Collaborator Author

/test horizon-operator-build-deploy-kuttl

@bshephar bshephar marked this pull request as ready for review February 15, 2025 23:27
This change does some refactoring of the deployment.go code to avoid
overuse of string literals and replace with consts. Along with moving excessive code
from the main Deployment function into dedicated functions that are easier to test
and read.

Signed-off-by: Brendan Shephard <[email protected]>
Signed-off-by: Brendan Shephard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants