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

[Feature] Show output in either table/yaml/json format for timoni inspect resources command #454

Closed
rrmistry opened this issue Dec 12, 2024 · 3 comments

Comments

@rrmistry
Copy link

rrmistry commented Dec 12, 2024

Business Problem Being Solved For

> External tool requires YAML manifests of all resources deployed by timoni

Context:

Currently, we are using Tilt which requires the YAML manifest of all resources deployed by an external tool (in this case timoni)

Reference: k8s_custom_deploy

Excerpt:

The apply_cmd ... should output the YAML of the objects it applied to the Kubernetes cluster to stdout. Tilt will track workload status and stream pod logs based on this result.

Work Around:

Currently, we are using a script like this to get the YAML manifest of all resources deployed by timoni:

#!/bin/bash

# Run timoni apply command and pipe the output to the while loop with prefix "#" to comment it out in YAML format
# Could have also ignored the output except if there is an error
timoni apply $RELEASE ./ --namespace $NAMESPACE 2>&1 | while read line; do echo "# $line"; done

# Run timoni inspect resources and store the output
resources=$(timoni inspect resources $RELEASE --namespace $NAMESPACE)

# Skip the header line and parse each resource
echo "$resources" | tail -n +2 | while read -r line; do
    echo "---" # Separator between resources

    # Extract resource type and name
    resource_type=$(echo "$line" | awk '{print $1}' | cut -d/ -f1)
    resource_name=$(echo "$line" | awk '{print $1}' | cut -d/ -f2)
    namespace=$(echo "$line" | awk '{print $2}')

    # Generate and run kubectl get command
    kubectl get "$resource_type" "$resource_name" --namespace "$namespace" --output YAML
done

Expected Outcome:

> Add a new flag for timoni inspect resources called --output with values table, yaml or json which can be used to get the YAML manifest of all resources deployed by timoni.


This great tool saves us a lot of time by abstracting CUE for Kubernetes.

Kudos! and much appreciation! 🙏

@rrmistry rrmistry changed the title [Feature] Show table/YAML/JSON format for timoni inspect resources command [Feature] Show output in either table/yaml/json format for timoni inspect resources command Dec 12, 2024
@stefanprodan
Copy link
Owner

stefanprodan commented Dec 14, 2024

timoni build does output all the resources in YAML format

@rrmistry
Copy link
Author

The external tool in question was very particular about requiring the complete YAML manifest from the Kubernetes API (🤦🏻 it wanted to track the .metadata.uid field from the output YAML). This made it not compatible with timoni build, which is a mainly client-side version of YAML manifests that doesn't contain the server-side field required.

I'll close this issue for now as I have moved on to a better workflow with timoni that doesn't require this server-side manifest.

My new workflow for anyone curious
  1. Transition from Tiltfile to Taskfile with file fingerprinting to prevent rework
  2. Use clever environment variables that tag docker images with local vs. remote registers
    • For docker build task
      • Set registry host for accompanying container registry
        env:
          REGISTRY_HOST:
            sh: |
              echo "localhost:$(k3d registry get "{{.CLUSTER_NAME}}" --output=json 2>/dev/null | jq -r 'try .[0].portMappings."5000/tcp"[0].HostPort catch "5000"')"
        
      • Push docker tag {{.REGISTRY_HOST}}/app/frontend:{{.BUILD_NUMBER}}
    • For timoni apply task
      • Set registry host for in-cluster host name:
        env:
          REGISTRY_HOST:
            sh: |
              echo "{{.CLUSTER_NAME}}:5000"
        
      • Set image in values as {{.REGISTRY_HOST}}/app/frontend:{{.BUILD_NUMBER}}
  3. Use task build --watch to use file watchers with file fingerprinting above

This replicates enough of my original workflow with Tilt that I can move away from it for now.

@salotz
Copy link

salotz commented Jan 8, 2025

@rrmistry FWIW I've been using Garden with timoni pretty successfully, which (I think) covers a lot of what you are trying to accomplish.

I can comment more somewhere to share tips if you are interested.

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

No branches or pull requests

3 participants