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

Retrieve application and pod statuses #1332

Merged
merged 15 commits into from
Aug 6, 2024

Conversation

omgoswami
Copy link
Contributor

added kubectl appstatus plugin which will validate the given instance of an application and return its status, along with the status of any application pods

@devdattakulkarni
Copy link
Contributor

@omgoswami 👍
Will go through the PR soon.

@omgoswami
Copy link
Contributor Author

I'm not sure why it's trying to merge 9 commits instead of only the most recent one -- any idea what's going on?

@devdattakulkarni
Copy link
Contributor

Check https://github.com/orgs/community/discussions/22787 for why this happens

There is no need to worry as long as the files shown/included as part of the PR are the ones that you have actually modified as part this issue's work.


Input: name of kind and name of application instance

TODO: reexamine all error checks for plugins
Copy link
Contributor

Choose a reason for hiding this comment

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

Get rid of TODO

or check if status contains an error
otherwise (i.e. status missing), display "App not deployed properly"
'''
# response = json.dumps(json.loads(out), indent=4)
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete.

@devdattakulkarni devdattakulkarni changed the title WIP: issue #1275 retrieve application and pod statuses Retrieve application and pod statuses Aug 2, 2024
return True
return False

'''
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this TODO?

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, I'm removing it now -- the method that that TODO describes was written right below it.

tests/tests.py Outdated
out, err = TestKubePlus.run_command(cmd)

# test plugin
cmd = "kubectl appstatus HelloWorldService hs1"
Copy link
Contributor

@devdattakulkarni devdattakulkarni Aug 2, 2024

Choose a reason for hiding this comment

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

Don't we have to pass "-k provider.conf" here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I was testing locally, it worked without -k provider.conf (as does appresources), but I will add it in.

tests/tests.py Outdated

def cleanup():
cmd = "cd ./hello-world"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than including ./hello-world directory in the tests folder, let's follow the pattern that we have used in test_application_update test, where we are referring to the files from the examples folder.

You can pretty much copy lines 90 till 117

if not TestKubePlus._is_kubeplus_running():

TestKubePlus.run_command(cmd)

tests/tests.py Outdated
# TODO: Add tests for
# kubectl connections
# kubectl appresources
# kubectl appurl
# kubectl applogs
# kubectl metrics
# TODO: pos test case for kubectl appstatus with HelloWorld
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete this TODO.


# test plugin
cmd = "kubectl appstatus HelloWorldService hs1"
out, err = TestKubePlus.run_command(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we write some assertions on the output?
Also, it will be good to print the output. That way, in the CI run we will be able to see how the output looks like.

@@ -0,0 +1,53 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

You have made this file executable, right? (chmod +x kubectl-appstatus)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

print(err)
exit(1)

release_name_or_status, release_ns, deployed, err = appStatusFinder.get_app_instance_status(kind, instance, kubeconfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need the last parameter since it is always returned as None.

exit(1)

release_name_or_status, release_ns, deployed, err = appStatusFinder.get_app_instance_status(kind, instance, kubeconfig)
if err is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this check. The error check is happening in lines 12-15.

else:
# an error has occurred
status = response['status']
return status, None, False, None
Copy link
Contributor

@devdattakulkarni devdattakulkarni Aug 2, 2024

Choose a reason for hiding this comment

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

I suggest defining variables for the second and third return parameters and setting their values after lines 21 and 25. That way, by looking at the return statement it will be clear what parameters are being returned.

@devdattakulkarni
Copy link
Contributor

Also, while the CI is passing, it might be because we don't have any asserts on the output in the test. So let's add some asserts on the output. There is also the below error in the CI run. I am not sure why it did not cause CI failure.

https://github.com/cloud-ark/kubeplus/actions/runs/10203383316/job/28229600641?pr=1332#step:5:4792

@omgoswami omgoswami reopened this Aug 5, 2024

# asserts
lines = out.split('\n')
self.assertTrue('Deployed' in lines[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the order of the lines always guaranteed to be such that the first line will be helm release and the second line will be Pods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! In the driver code for the plugin in plugins/appstatus.py, I am printing the helmrelease first and then iterating through all of the pods in the namespace afterwards.

tests/tests.py Outdated Show resolved Hide resolved
tests/tests.py Outdated Show resolved Hide resolved
tests/tests.py Outdated
return

# register HelloWorldService API
cmd = "kubectl create -f ../examples/multitenancy/hello-world/hello-world-service-composition.yaml --kubeconfig=%s" % provider
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to:
hello-world-service-composition-local.yaml.

hello-world-service-composition uses the 0.0.2 version of the chart.

hello-world-service-composition-local uses the 0.0.3 version of the chart.

The 0.0.3 version of the chart has replicas field in values.yaml

tests/tests.py Outdated
def cleanup():
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hs1.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hello-world-service-composition.yaml --kubeconfig=%s" % provider
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to: hello-world-service-composition-local.yaml

@devdattakulkarni devdattakulkarni merged commit effd6a9 into cloud-ark:master Aug 6, 2024
1 check passed
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