Custom Pricing Upload Script
π Key Features
- Define cloud instance pricing data in YAML
- Specify Kubernetes connection details (via kubeconfig and kubecontext) in the same YAML
- Automatically port-forward to a Kubernetes service
- Convert the YAML pricing info to CSV
- Upload the CSV to a pricing API running inside the cluster
π Files
- custom-pricing-data.yaml: YAML input file with Kubernetes config and pricing data
- custom-pricing-upload.sh: Bash script to read YAML, port-forward, generate CSV, and upload
π¦ Prerequisites
Make sure the following tools are installed:
- kubectl: Communicate with Kubernetes
- yq: Parse YAML in shell
- jq: Parse JSON in shell
- curl: Upload CSV via API
Input custom-pricing-data YAML Format
The input YAML file should follow this format:
kubernetes:
kubeconfig: "" #absolute path og kubeconfig
kubecontext: "" #kubecontext name
namespace: "kubeslice-controller"
service: "kubetally-pricing-service"
#we can add as many cloud providers and instance types as needed
cloud_providers:
- name: "gcp"
instances:
- region: "us-east1"
component: "Compute Instance"
instance_type: "a2-highgpu-2g"
vcpu: 1
price: 20
gpu: 1
- region: "us-east1"
component: "Compute Instance"
instance_type: "e2-standard-8"
vcpu: 1
price: 5
gpu: 0
Running the Script
Make the script executable:
chmod +x custom-pricing-upload.sh
Run the script:
./custom-pricing-upload.sh
Summary
- Reads Kubernetes config from YAML
- Auto-discovers the service port (e.g., kubetally-pricing-service:80)
- Picks a random local port
- Starts a background port-forward to that service
- Converts pricing data in YAML β CSV
- Uploads CSV to:
http://localhost:<random_port>/api/v1/prices
π Notes
- Ensure the YAML configuration file is correctly formatted and contains all necessary fields. π
- The script will exit with an error if any critical steps fail unless configured to skip on failure. β
- Paths specified in the YAML file should be relative to the
base_pathunless absolute paths are used. π
π οΈ Troubleshooting
- Missing Binaries: Ensure all required binaries are installed and accessible in your systemβs
PATH. β οΈ - Cluster Access Issues: Verify that kubeconfig files are correctly configured and that the script can access the clusters specified in the YAML configuration. π§
- Timeouts: If a component fails to install within the specified timeout, increase the
verify_install_timeoutin the YAML file. β³