Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

✨ Added api for kubernetes resource health check#379

Merged
abdheshnayak merged 1 commit into
release-v1.0.8from
feat/kube-resource-health-api
Oct 7, 2024
Merged

✨ Added api for kubernetes resource health check#379
abdheshnayak merged 1 commit into
release-v1.0.8from
feat/kube-resource-health-api

Conversation

@abdheshnayak
Copy link
Copy Markdown
Contributor

@abdheshnayak abdheshnayak commented Oct 7, 2024

  • added api for kubernetes resources health check

Summary by Sourcery

Add a new application for Kubernetes resource health checks with endpoints for general health, Kubernetes API health, and specific service health checks. Include a Taskfile for managing build and deployment tasks.

New Features:

  • Introduce a new API for checking the health of Kubernetes resources, including endpoints for overall health, Kubernetes API health, and specific service health checks.

Build:

  • Add a Taskfile.yml to manage tasks such as running the application, building the binary for different architectures, and building and pushing Docker images.

@abdheshnayak abdheshnayak merged commit 959dfea into release-v1.0.8 Oct 7, 2024
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 7, 2024

Reviewer's Guide by Sourcery

This pull request adds a new API for Kubernetes resource health checks. It introduces a new Go application that creates an HTTP server to handle health check requests for Kubernetes services and their associated pods.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implement main application logic for Kubernetes health checks
  • Create a Fiber web server with various endpoints
  • Implement environment variable loading
  • Set up Kubernetes client configuration
  • Add health check logic for services and pods
  • Implement error handling and logging
apps/kube-health/main.go
Add build and run tasks for the application
  • Define tasks for running the application
  • Add build tasks for different architectures
  • Include a task for building and pushing Docker containers
apps/kube-health/Taskfile.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@abdheshnayak abdheshnayak deleted the feat/kube-resource-health-api branch October 7, 2024 04:03
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @abdheshnayak - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider implementing more robust error handling instead of using panic() in the Run() function. This would improve the service's reliability and make it easier to diagnose issues in production.
  • Ensure proper authentication and authorization mechanisms are in place for accessing Kubernetes API information through this service to maintain security.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread apps/kube-health/main.go
return &e, nil
}

func main() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Consider more graceful error handling in main()

Instead of using panic(), consider logging the error and performing a controlled shutdown. This approach is more suitable for a production Kubernetes service.

func main() {
	if err := Run(); err != nil {
		log.Printf("Error running application: %v", err)
		os.Exit(1)
	}

Comment thread apps/kube-health/main.go
count := 0
// Check the status of each pod
for _, pod := range pods.Items {
if err := checkPodHealth(&pod); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Avoid logging errors within checkSvcHealth

Consider returning errors from this function instead of logging them here. This allows for better separation of concerns and more flexible error handling at higher levels of the application.

		err := checkPodHealth(&pod)
		if err != nil {
			count++
			return fmt.Errorf("pod health check failed: %w", err)
		}

Comment thread apps/kube-health/main.go
"k8s.io/client-go/rest"
)

type Env struct {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 suggestion (security): Validate KubernetesApiProxy value

Consider adding validation for the KubernetesApiProxy value, especially since it's used directly in the rest.Config. This can help prevent security issues and improve reliability.

type Env struct {
	HttpPort           uint16 `env:"HTTP_PORT" default:"3000"`
	KubernetesApiProxy string `env:"KUBERNETES_API_PROXY" validate:"required,url"`

abdheshnayak added a commit that referenced this pull request Nov 5, 2024
✨ Added api for kubernetes resource health check
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant