#variant

variant

Archived
01,388

Discuss variant (the “Universal CLI”) https://github.com/mumoshu/variant

Archive: https://archive.sweetops.com/variant/

erik
erikover 1 year ago
archived the channel
Robert Horrox
Robert Horroxalmost 6 years ago
Not sure if this channel is best to discuss atmos (https://github.com/cloudposse/atmos) when using the config stack if a component hasn’t been defined at any level in the config files it will still return the full global config instead of error’ing out. Not sure if this is the intended behavior or a side effect of the multi layer import configs.
mumoshu
mumoshuabout 6 years ago
You can now turn your Variant2 command into a Kubernetes controller :simple_smile:
See https://github.com/mumoshu/variant2/pull/35
mumoshu
mumoshuabout 6 years ago
also - it may theoretically possible to export your variant-made command as a porter bundle by using https://porter.sh/custom-dockerfile/.
mumoshu
mumoshuabout 6 years ago
variant is mostly a HCL-based DSL and the compiler to build CLI apps. So my guess is that porter should be used to package variant-made apps 🙂
Amit Karpe
Amit Karpeabout 6 years ago
I found Porter a project which was accepted by the CNCF recently.
I am still trying to understand whether it is close to what variant dose!

Package your application artifact, client tools, configuration and deployment logic together as a versioned bundle that you can distribute, and then install with a single command
mumoshu
mumoshuabout 6 years ago
Turns out Waypoint is not make or variant at all. It's a pluggable PaaS powered by not cli only but also waypoint-entrypoint and waypoint-server :simple_smile:

Probably we may use variant to wrap waypoint-cli or call variant commands via waypoint's exec plugin
mumoshu
mumoshuabout 6 years ago(edited)
Apparently you can start from no server, and gradually move heavy processes to the waypoint server in the future

https://www.waypointproject.io/docs/roadmap#remote-runners
mumoshu
mumoshuabout 6 years ago
mumoshu
mumoshuabout 6 years ago
Probably variant could be handy when used from waypoint hooks(https://www.waypointproject.io/docs/lifecycle/hooks) and exec plugin(https://www.waypointproject.io/plugins/exec)
mumoshu
mumoshuabout 6 years ago
@Erik Osterman (Cloud Posse) Just read the announcement. Looks nice!
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 6 years ago
erik
erikabout 6 years ago
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)about 6 years ago
johncblandii
johncblandiiabout 6 years ago
@mumoshu any thoughts on this error? (see first comment)

This was working fine and is now failing with no changes to the variant files or the build approach.
Robert Horrox
Robert Horroxover 6 years ago
I’m hoping someone knows the answer to this, I’m working with variant2 and variantmod and I’m trying to pull an entire directory using variant. I can’t only figure out how to pull single files. I see in the code that Directories are supported in some fashion, I just can’t figure out the right config to pull them
johncblandii
johncblandiiover 6 years ago
@Erik Osterman (Cloud Posse) @mumoshu here is an example of a CLI call not waiting for input.

I don’t have the exact code in play right here, but my guess it is the workspace running then it immediately goes to a init which also skips waiting for the input.

Initializing modules...

Initializing the backend...
Backend configuration changed!

Terraform has detected that the configuration specified for the backend
has changed. Terraform will now check for existing state in the backends.


Do you want to migrate all workspaces to "s3"?
  Both the existing "s3" backend and the newly configured "s3" backend
  support workspaces. When migrating between backends, Terraform will copy
  all workspaces (with the same names). THIS WILL OVERWRITE any conflicting
  states in the destination.
  
  Terraform initialization doesn't currently migrate only select workspaces.
  If you want to migrate a select number of workspaces, you must manually
  pull and push those states.
  
  If you answer "yes", Terraform will migrate all states. If you answer
  "no", Terraform will abort.

  Enter a value: 
Do you want to migrate all workspaces to "s3"?
  Both the existing "s3" backend and the newly configured "s3" backend
  support workspaces. When migrating between backends, Terraform will copy
  all workspaces (with the same names). THIS WILL OVERWRITE any conflicting
  states in the destination.
  
  Terraform initialization doesn't currently migrate only select workspaces.
  If you want to migrate a select number of workspaces, you must manually
  pull and push those states.
  
  If you answer "yes", Terraform will migrate all states. If you answer
  "no", Terraform will abort.

  Enter a value: 

Error: Migration aborted by user.
johncblandii
johncblandiiover 6 years ago
another interesting one, @mumoshu.

Parsing this YAML works fine:

    order:
      - job: terraform plan eks
        args: ""
      - job: helmfile diff teleport
        args: --selector chart=teleport-node

Parsing this YAML seems to have a problem with:

    order:
      - job: terraform plan eks
        # args: ""
      - job: helmfile diff teleport
        args: --selector chart=teleport-node

It throws the following error, but the issue is a missing args not a missing job:

Error: Missing map element

  on ../cli/trigger.variant line 36:
  (source code not available)

This map does not have an element with the key "job".

Error: ../cli/trigger.variant:36,29-33: Missing map element; This map does not have an element with the key "job".
johncblandii
johncblandiiover 6 years ago
@mumoshu I’m getting weird results from simply reading my file.

contents:

triggers:
  smoke-test:
    description: Smoke testing the CLI
    order:
      - job: terraform plan eks
        args:
          - -detailed-exitcode

error:

panic: inconsistent map element types (cty.List(cty.String) then cty.String)

goroutine 1 [running]:
<http://github.com/zclconf/go-cty/cty.MapVal(0xc0009ea880|github.com/zclconf/go-cty/cty.MapVal(0xc0009ea880>, 0xc0009ea880, 0xc0009d20f8, 0x3, 0xc0009ea9b8)
        /home/runner/go/pkg/mod/github.com/zclconf/go-cty@v1.2.1/cty/value_init.go:207 +0x4b3
<http://github.com/mumoshu/variant2/pkg/app.goToCty(0x1767100|github.com/mumoshu/variant2/pkg/app.goToCty(0x1767100>, 0xc0004d38f0, 0x0, 0x0, 0x1, 0xc0009bb8e0, 0x0, 0x1)
        /home/runner/work/variant2/variant2/pkg/app/go_to_cty.go:28 +0x60e
<http://github.com/mumoshu/variant2/pkg/app.(*App).execMultiRun(0xc0000e3140|github.com/mumoshu/variant2/pkg/app.(*App).execMultiRun(0xc0000e3140>, 0xc000239580, 0xc000819280, 0xc0009eadf8, 0x16, 0xc0009d1160, 0x16)
        /home/runner/work/variant2/variant2/pkg/app/app.go:1214 +0x13f
<http://github.com/mumoshu/variant2/pkg/app.(*App).execJob(0xc0000e3140|github.com/mumoshu/variant2/pkg/app.(*App).execJob(0xc0000e3140>, 0xc000239580, 0xc0000bd997, 0x7, 0x0, 0x205fbc0, 0xc0006fc540, 0xc0000c7610, 0xc000577ea0, 0x2, ...)
        /home/runner/work/variant2/variant2/pkg/app/app.go:816 +0x246
<http://github.com/mumoshu/variant2/pkg/app.(*App).Job.func1(0x0|github.com/mumoshu/variant2/pkg/app.(*App).Job.func1(0x0>, 0x0, 0x0)
        /home/runner/work/variant2/variant2/pkg/app/app.go:644 +0x939
<http://github.com/mumoshu/variant2/pkg/app.(*App).Run(0xc0000e3140|github.com/mumoshu/variant2/pkg/app.(*App).Run(0xc0000e3140>, 0xc0000bd997, 0x7, 0xc00080adb0, 0xc00080ade0, 0xc00020b9e0, 0x1, 0x1, 0x0, 0x0, ...)
        /home/runner/work/variant2/variant2/pkg/app/app.go:513 +0xc3
<http://github.com/mumoshu/variant2.(*Runner).Cobra.func1(0xc00037d180|github.com/mumoshu/variant2.(*Runner).Cobra.func1(0xc00037d180>, 0xc00080acf0, 0x2, 0x3, 0x0, 0x0)
        /home/runner/work/variant2/variant2/variant.go:661 +0x114
<http://github.com/spf13/cobra.(*Command).execute(0xc00037d180|github.com/spf13/cobra.(*Command).execute(0xc00037d180>, 0xc00080ac00, 0x3, 0x3, 0xc00037d180, 0xc00080ac00)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:826 +0x460
<http://github.com/spf13/cobra.(*Command).ExecuteC(0xc0000e9b80|github.com/spf13/cobra.(*Command).ExecuteC(0xc0000e9b80>, 0x2034ba0, 0xc0000be010, 0x2034ba0)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x2fb
<http://github.com/spf13/cobra.(*Command).Execute(...)|github.com/spf13/cobra.(*Command).Execute(...)>
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
<http://github.com/mumoshu/variant2.(*Runner).Run(0xc0007c3040|github.com/mumoshu/variant2.(*Runner).Run(0xc0007c3040>, 0xc0000f8c90, 0x4, 0x4, 0xc00020bd78, 0x1, 0x1, 0x0, 0x0)
        /home/runner/work/variant2/variant2/variant.go:791 +0x2cc
<http://github.com/mumoshu/variant2.Main.Run(0x7ffe211094bb|github.com/mumoshu/variant2.Main.Run(0x7ffe211094bb>, 0x3, 0x0, 0x0, 0x0, 0x7ffe211094b4, 0xa, 0x2034ba0, 0xc0000be008, 0x2034ba0, ...)
        /home/runner/work/variant2/variant2/variant.go:396 +0x12d
main.main()
        /home/runner/work/variant2/variant2/pkg/cmd/main.go:13 +0xb8
johncblandii
johncblandiiover 6 years ago
0.28 seems to be pretty solid. tests are passing with no changes.
nian
nianover 6 years ago
For variant … this tool appears to be running locally, as opposed to something in a cluster from the local terminal. Is that correct?
johncblandii
johncblandiiover 6 years ago
@mumoshu can a variable not reference a config?
johncblandii
johncblandiiover 6 years ago
@mumoshu it seems options are not available to a job when it is used as a source of a config

  config "state" {
    source job {
      name = "state"
      args = {
        tenant = param.tenant
      }
      key = "key"
      format = "text"
    }
  }

that works, but it does not recognize the opts.tenants-dir in the state job and it does recognize the opt when I call it directly
johncblandii
johncblandiiover 6 years ago
@mumoshu along the lines of the previous question, can you do a source dynamically (only pull if param.x exists) or try/catch on a failed source load?
johncblandii
johncblandiiover 6 years ago
@mumoshu was talking with @Erik Osterman (Cloud Posse) about a new cli command and it’d be clean if I could use an if statement on an internal depends_on. is that possible?
johncblandii
johncblandiiover 6 years ago
I think there is a regression in 0.24.2. the tests worked in 0.24.0 and now fail with:

  26:       aws --profile ${var.namespace}-${var.tenant}-helm eks update-kubeconfig --name=${var.namespace}-${var.tenant}-eks-cluster --region=${var.region} --kubeconfig=${var.kubeconfig-path}/kubecfg.${var.tenant}-helm

There is no variable named "var".
johncblandii
johncblandiiover 6 years ago(edited)
btw, @mumoshu, I was able to completely write full CLI coverage with 0 knowledge of the test approach within a day of work for about 15+ commands
johncblandii
johncblandiiover 6 years ago
(sorry about the flood today; digging into a new area with variant2) 🙂
johncblandii
johncblandiiover 6 years ago
I can’t pinpoint why this is failing. Any thoughts here, @mumoshu? I tried wrapping the run.res.exitstatus in trimspace since case.exitstatus used it too.

 (string)--- FAIL: deploy (0.06s)
    --- FAIL: deploy/ok (0.05s)
        app.go:1040: case "ok": assertion "out" failed: this expression must be true, but was false: run.res.stdout == case.out
            , where run.res.stdout=------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project1
            ------------------------------------------------------------------------
            terraform deploy project1 
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project2
            ------------------------------------------------------------------------
            terraform deploy project2 
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying helmfile project: project1
            ------------------------------------------------------------------------
            helmfile apply project1 
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying helmfile project: project2
            ------------------------------------------------------------------------
            helmfile apply project2 
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project3
            ------------------------------------------------------------------------
            terraform deploy project3 
            
             (string) case.out=------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project1
            ------------------------------------------------------------------------
            terraform deploy project1
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project2
            ------------------------------------------------------------------------
            terraform deploy project2
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying helmfile project: project1
            ------------------------------------------------------------------------
            helmfile apply project1
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying helmfile project: project2
            ------------------------------------------------------------------------
            helmfile apply project2
            
            ------------------------------------------------------------------------
            [CLIENT] Deploying terraform project: project3
            ------------------------------------------------------------------------
            terraform deploy project3
             (string)
FAIL
Error: test exited with code 1
johncblandii
johncblandiiover 6 years ago
@mumoshu i think something is up with global options again. this bool option I can echo at the top level and it is true. then in jobs run from that job it is false.

deploy (dry-run = true) -> helmfile deploy (dry-run = false)

➜ ./nbo deploy acme --tenants-dir=../tenants --dry-run --kubeconfig-path=~/.kube

INTERNAL: dry? false. kc-path? /dev/shm

TOP-LEVEL: dry? true. kc-path? ~/.kube

the kc opt is a string and dry is a bool. those should both internally be different values.
johncblandii
johncblandiiover 6 years ago
@mumoshu can we get some output clean-up on test failures? separating the runs + their failures and maybe some color coding would really help with readability.

https://github.com/mumoshu/variant2/issues/20
johncblandii
johncblandiiover 6 years ago(edited)
@mumoshu I’d like to dynamically run different parameters to run and reference them in my case without manually typing them again. case.* access seems only available in a run or assert and not within the case itself or in variable.

example from https://github.com/mumoshu/variant2/blob/9753895bdea9bd949596159aaf2f3f9f489575dc/examples/concurrency/concurrency_test.variant:

  case "ng1" {
    concurrency = 0
    err = "delay of ${case.delayone} is less than ${case.delaytwo}"
    stdout = ""
    delayone = 0
    delaytwo = 1
  }

  run "test" {
    concurrency = case.concurrency
    delayone = case.delayone
    delaytwo = case.delaytwo
  }

instead of having type type:

err = "delay of 0 is less than 1"

…which then requires me to change 0 in multiple places if I change the value of delayone to anything else.
johncblandii
johncblandiiover 6 years ago
@mumoshu I’m working with tests and it seems null should be allowed for err as opposed to requiring an empty string.

  case "ok" {
    tenant = "acme"
    exitstatus = 0
    err = ""
  }

^ this works just fine.

take err out and you get an error: This object does not have an attribute named "err".

set it to err = null and you get:

panic: handler for type dynamic not implemented yet [recovered]
        panic: handler for type dynamic not implemented yet

goroutine 10 [running]:
testing.tRunner.func1(0xc0000cb500)
        /opt/hostedtoolcache/go/1.13.10/x64/src/testing/testing.go:874 +0x3a3
panic(0x21ebee0, 0xc0000968e0)
        /opt/hostedtoolcache/go/1.13.10/x64/src/runtime/panic.go:679 +0x1b2
<http://github.com/mumoshu/variant2/pkg/app.(*App).execAssert(0xc00020b080|github.com/mumoshu/variant2/pkg/app.(*App).execAssert(0xc00020b080>, 0xc0005cc980, 0xc0004dda0a, 0x5, 0x2840660, 0xc000598a80, 0x0, 0x0)
        /home/runner/work/variant2/variant2/pkg/app/app.go:965 +0x9d0
<http://github.com/mumoshu/variant2/pkg/app.(*App).execTestCase(0xc00020b080|github.com/mumoshu/variant2/pkg/app.(*App).execTestCase(0xc00020b080>, 0xc000035740, 0x12, 0xc0005b5ec0, 0x1, 0x1, 0xc0005ab5e0, 0x1, 0x1, 0xc000035820, ...)
        /home/runner/work/variant2/variant2/pkg/app/app.go:1091 +0x659
<http://github.com/mumoshu/variant2/pkg/app.(*App).execTest.func1(0xc0000cb500)|github.com/mumoshu/variant2/pkg/app.(*App).execTest.func1(0xc0000cb500)>
        /home/runner/work/variant2/variant2/pkg/app/app.go:1037 +0xc2
testing.tRunner(0xc0000cb500, 0xc0005be790)
        /opt/hostedtoolcache/go/1.13.10/x64/src/testing/testing.go:909 +0xc9
created by testing.(*T).Run
        /opt/hostedtoolcache/go/1.13.10/x64/src/testing/testing.go:960 +0x350
Zachary Loeber
Zachary Loeberover 6 years ago
sorry 😞
Zachary Loeber
Zachary Loeberover 6 years ago
I think they use buffalo framwork behind the scenes but, again, I'm barely scratching at this particular itch of mine yet
Zachary Loeber
Zachary Loeberover 6 years ago
I've been seeking such a bullet myself. I was going to look towards some of the fairwinds projects for inspiration (https://github.com/FairwindsOps/polaris for instance) as they seem to use pure Go based solutions but I haven't gotten that far yet. Most solutions I've seen incorporate some java frameworks that instantly turn me off.
Zachary Loeber
Zachary Loeberover 6 years ago
@Zachary Loeber has joined the channel
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)over 6 years ago

Where's/What's the silver bullet for building an enterprise-grade Web UI today?
Erik Osterman (Cloud Posse)
Erik Osterman (Cloud Posse)over 6 years ago
@Zachary Loeber you have a pulse on everything. Question for you: https://github.com/mumoshu/variant2/issues/17#issuecomment-617835218
mumoshu
mumoshuover 6 years ago
thx!
johncblandii
johncblandiiover 6 years ago
Issue created for building with a . as the path: https://github.com/mumoshu/variant2/issues/19
johncblandii
johncblandiiover 6 years ago
Context:

order:
  - terraform.account
  - terraform.iam-tenant-roles
  - terraform.cloudtrail
  - terraform.vpc

deploy job:

  depends_on "deploy switch" {
    items = conf.file.order

    args = {
      item   = item
      tenant = param.tenant
    }
  }

switch is the job that splits the left/right of the . and calls an internal job

job "deploy switch" {
  run {
    job = "${var.subcommand} deploy"

    with = {
      project = var.project
      tenant  = param.tenant
    }
  }
}

johncblandii
johncblandiiover 6 years ago

this seems like building a dependency graph that each next job depends on its previous job?

i guess you could call it one, but that’s not the intent. it isn’t a dependency as in the cli depends on job 1 to run for 2. it is a dependency in how we’re managing our config file for looping
johncblandii
johncblandiiover 6 years ago
yes, i saw different behavior. i’ll try to replicate
mumoshu
mumoshuover 6 years ago
are you seeing different behavior?
mumoshu
mumoshuover 6 years ago
and depends_on items should be executed serially and stop on the first error
mumoshu
mumoshuover 6 years ago

exec jobs in a loop and stop when they fail

this seems like building a dependency graph that each next job depends on its previous job? 🤔

but anyways,

[10:35 AM] Is there a concept of looping outside of depends on?

no
johncblandii
johncblandiiover 6 years ago
Is there a concept of looping outside of depends on?