fi-ts / cloudctl

Command-line client for FI-TS Finance Cloud Native services
MIT License
9 stars 6 forks source link

[feature-request] provide patch and apply [sub-]commands #308

Open TLINDEN opened 2 months ago

TLINDEN commented 2 months ago

In cloudctl, just like with kubectl, you can work either with commands and params or directly edit manifests. However, that's the only way to manipulate manifests.

A patch and apply command (or subcommand to other commands) would be very nice to have.

Consider this hack to be able to scale up/down a posgres instance:

pgscale() {
    local value=$1
    local uid=$2

    if test -z "$uid"; then
        echo "Usage: pgscale <value> <postgres-id>"
        return
    fi

    pgpatch .numberofinstances $value $uid
}

pgpatch() {
    local attribute=$1
    local value=$2
    local uid=$3

    if test -z "$uid"; then
        echo "Usage: pgpatch <yaml-attr> <value> <postgres-id>"
        return
    fi

    script="/tmp/pgpatch-$$"
    echo "#!/bin/sh
file=\$1
yq e -i '$attribute |= $value' \$file
" > $script

    chmod 700 $script

    EDITOR="$script" c postgres edit $uid

    rm -f $script
}

How much better would it be to just call cloudctl postgres patch..., wouldn't it?

Gerrit91 commented 2 weeks ago

For metalctl we have this functionality throughout the entire CLI and it's implemented through metal-lib's GenericCLI package. We are working towards adaption of this library for cloudctl, too.

However, this also brings some risk. We do not guarantee non-breaking API changes for the time being because we have no real API versioning in place like Kubernetes does it. When people start to automate cluster creation through apply commands for example and something in the API changes this could lead to very risky scenarios. This is why we were hesitating with these kind of things for the cloud-api.

GenericCLI also shows the request sent to the API in case a TTY is detected, such that the user has the possibility to review before apply, but the breaking API changes problem remains. Unfortunately, the API design is a bit different from Kubernetes.

❯ metalctl partition apply -f partition.yaml
applying ["fra"], continue?

bootconfig:
    commandline: console=ttyS1,115200n8 ip=dhcp carrier_timeout=10 DEBUG=1
    imageurl: http://github.com/metal-stack/metal-hammer/releases/download/v0.13.6/metal-hammer-initrd.img.lz4
    kernelurl: http://github.com/metal-stack/kernel/releases/download/6.6.50-37/metal-kernel
description: Metal Test environment in Frankfurt
id: fra
name: Frankfurt
privatenetworkprefixlength: 22

 [y]