TykTechnologies / tyk

Tyk Open Source API Gateway written in Go, supporting REST, GraphQL, TCP and gRPC protocols
Other
9.76k stars 1.09k forks source link

[TT-12626] create k8s development testing guideline for gw/dash #6518

Open andrei-tyk opened 2 months ago

andrei-tyk commented 2 months ago

User description

https://tyktech.atlassian.net/browse/TT-12626

Description

Added some scripts and makefile targets to allow for easier deployment of Tyk in K8S for development and testing purposes.

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

Checklist


PR Type

enhancement, documentation


Description


Changes walkthrough 📝

Relevant files
Enhancement
Makefile
Add Kubernetes kind cluster management to Makefile             

Makefile
  • Added CLUSTER_NAME variable for kind cluster naming.
  • Introduced create-kind-cluster and delete-kind-cluster targets.
  • Enhanced Makefile for Kubernetes development workflow.
  • +11/-0   
    Documentation
    k8sREADME.md
    Add Kubernetes development and testing guidelines               

    k8s/k8sREADME.md
  • Added installation instructions for Kubernetes tools.
  • Provided steps for creating and deleting a kind cluster.
  • Included instructions for managing Helm values.
  • Documented namespace creation and Redis installation.
  • +55/-0   
    Configuration changes
    kind.yaml
    Define kind cluster configuration for Kubernetes                 

    k8s/kind.yaml
  • Defined a kind cluster configuration with port mappings.
  • Configured roles for control-plane and worker nodes.
  • +11/-0   

    💡 PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    github-actions[bot] commented 2 months ago

    API Changes

    no api changes detected
    github-actions[bot] commented 2 months ago

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Possible Bug
    The 'clean' target is redefined to delete the kind cluster. This could unintentionally replace the standard 'clean' behavior which usually cleans build artifacts. Incomplete Documentation
    The documentation for installing required dependencies in the kind cluster is incomplete. The section on installing Redis ends abruptly without providing the necessary commands.
    github-actions[bot] commented 2 months ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Enhancement
    Complete the Redis installation command ___ **The section on installing Redis is incomplete. It's important to provide the full
    command needed to install Redis in the kind cluster to avoid confusion.** [k8s/k8sREADME.md [53]](https://github.com/TykTechnologies/tyk/pull/6518/files#diff-bcc443b5f3ade9cd91f4f9c836801d7f9d562d5b6b3a91948ffdc0dc2ab33d46R53-R53) ```diff #### - Redis +```bash +helm install redis bitnami/redis --namespace tyk +``` ```
    Suggestion importance[1-10]: 9 Why: Completing the Redis installation command is important for providing clear and complete instructions, preventing user confusion and errors.
    9
    Maintainability
    Rename the 'clean' target to 'delete-cluster' for clarity ___ **The target 'clean' is typically used for removing files that were created by the
    build process. Using 'clean' to delete a kind cluster might be misleading. Consider
    renaming this target to something more descriptive like 'delete-cluster' or
    'clean-cluster'.** [Makefile [104-105]](https://github.com/TykTechnologies/tyk/pull/6518/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R104-R105) ```diff -clean: ## Delete kind cluster +delete-cluster: ## Delete kind cluster kind delete cluster --name=${CLUSTER_NAME} ```
    Suggestion importance[1-10]: 8 Why: Renaming the 'clean' target to 'delete-cluster' enhances clarity and maintainability, reducing potential confusion about its purpose.
    8
    Best practice
    Replace hardcoded default values with configurable options ___ **It's a good practice to avoid hardcoding values directly in the Makefile. Instead,
    consider using environment variables or configuration files that can be sourced.
    This makes the Makefile more flexible and easier to maintain.** [Makefile [22]](https://github.com/TykTechnologies/tyk/pull/6518/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R22-R22) ```diff -CLUSTER_NAME ?= kind +include config.env +CLUSTER_NAME ?= $(DEFAULT_CLUSTER_NAME) ```
    Suggestion importance[1-10]: 7 Why: The suggestion to replace hardcoded values with configurable options improves flexibility and maintainability, but it is not crucial for functionality.
    7
    Add error handling to installation commands ___ **The installation instructions for 'helm' and 'kind' are missing error handling.
    Consider adding checks to ensure that the commands were successful before
    proceeding.** [k8s/k8sREADME.md [10-17]](https://github.com/TykTechnologies/tyk/pull/6518/files#diff-bcc443b5f3ade9cd91f4f9c836801d7f9d562d5b6b3a91948ffdc0dc2ab33d46R10-R17) ```diff -$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 -$ chmod 700 get_helm.sh -$ ./get_helm.sh -go install sigs.k8s.io/kind@v0.23.0 +$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && echo "Downloaded Helm script successfully" || echo "Failed to download Helm script" +$ chmod 700 get_helm.sh && echo "Permission set successfully" || echo "Failed to set permission" +$ ./get_helm.sh && echo "Helm installed successfully" || echo "Failed to install Helm" +go install sigs.k8s.io/kind@v0.23.0 && echo "Kind installed successfully" || echo "Failed to install Kind" ```
    Suggestion importance[1-10]: 6 Why: Adding error handling to installation commands is a good practice for robustness, but it is not critical for the basic functionality of the instructions.
    6
    sonarcloud[bot] commented 2 months ago

    Quality Gate Passed Quality Gate passed

    Issues
    0 New issues
    0 Accepted issues

    Measures
    0 Security Hotspots
    0.0% Coverage on New Code
    0.0% Duplication on New Code

    See analysis details on SonarCloud