Git Product home page Git Product logo

Comments (4)

squaremo avatar squaremo commented on June 11, 2024

Hi Alex, which bit do you want to use with Node? Do you want to, e.g., use @jkcfg/std from a Node.JS script? Or something else.

from jk.

alexec avatar alexec commented on June 11, 2024

Maybe I should explain why I'm asking all these questions. I work on Argo CD and Argo Workflows. I'm trying to see if I can use JK to template apps because Helm, Kustomize, and Jsonnet don't do what I need.

I have around 160 apps to template, one for each Kubernetes cluster. These apps are largely homogenic - BUT not quite.

All the clusters are listed in a single YAML file which is generated by combining three other JSON files and a CSV, which is done using a Golang script. The output is

- arn: arn:aws:acm:us-west-2:469802291...
  bu: sbg ;# this business uint
  hostName: ;# the host name of the ingress
  ingress: true
  name: my-cluster.cluster.k8s.local
  server: https://REDACTED.west-2.elb.amazonaws.com
  splunk: https://REDACTED
  type: preprod ;# or prod
  wave: 3 ;# which release wave they go in and therefore which manifests and images they are based

So I have one control-plane app in Argo CD that create one app for each cluster (this is know as "app-of-apps").

So those apps should use one script to generate the YAML.

For Argo CD to support JK in this use case we need to:

  • (a) Install JK as a custom plugin.
  • (b) Parameterize the build based on the cluster name (which will be the app's name).

Argo CD requires you print the YAML to stdout, not to a file, e.g.:

  print(manifests, {
                format: Format.YAMLStream
            });

An you must invoke jk run main.js not jk generate main.js (aside - I tried path: '/dev/stdout' - it did not seem to work).

The way you parametrize a build in Argo CD is using environment variables. ARGOCD_APP_NAME; is the app name, which is also the cluster name.

So I have a script to generate the control plane:

read("data/cluster-configs.yaml").then(cs => {
    const apps = cs.map(c => {
...
        return m;
    });
    print(apps, {format: Format.YAMLStream});
});

An one to generate each cluster app:

read("data/cluster-configs.yaml").then(cs => {
    const c = cs.find(c => c.name = cluster);
    read("base/wave" + c.wave + "/image-tag.json", {
        format: Format.Raw
    }).then(imageTag => {
        read(
            "src/argo-workflows/base/wave" + c.wave + "/resources/upstream.yaml",
            {format: Format.YAMLStream}
        ).then(upstream => {
     

I thought I could do this using:

const cluster = process.ENV.ARGOCD_APP_NAME;

But that does not seem to work?

from jk.

alexec avatar alexec commented on June 11, 2024

If you have time, it'd be great to Zoom about this.

from jk.

squaremo avatar squaremo commented on June 11, 2024

Argo CD requires you print the YAML to stdout, not to a file, e.g.:

You can get jk generate to print to stdout with jk generate --stdout. The draft documentation in jkcfg/website#39 (files on that branch) go a little way towards explaining run vs generate and the rest.

The way you parametrize a build in Argo CD is using environment variables. ARGOCD_APP_NAME; is the app name, which is also the cluster name.

There's no access to environment variables from within a script, at present. You will need to wrap jk in a shell script that translates environment variables to parameters passed to jk at invocation, or the equivalent.

"src/argo-workflows/base/wave" + c.wave + "/resources/upstream.yaml"

A slightly neater way to construct strings is

`src/argo-workflows/base/wave${c.wave}/resources/upstream.yaml`

(backticks deliberate)

from jk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.