1. 29 Nov, 2017 1 commit
    • Alex Clemmer's avatar
      💪 Make env-name a required param in "env commands" · 4923a3f5
      Alex Clemmer authored
      
      
      Fixes #100.
      
      This commit will transition the ksonnet CLI away from accepting either a
      list of files or an environment (or both). A detailed explanation
      follows.
      
      Historically, the ksonnet CLI has had several "environment commands".
      These commands (e.g., `apply`, `diff`, `delete`, `show`, etc.) all took
      one of the following:
      
        1. An environment name. For example, `apply us-west/dev` will `apply`
           everything in the `components/` directory to the cluster denoted by
           `us-west/dev`.
        2. A set of files. For example, `apply -f foo.jsonnet -f bar.jsonnet`
           would apply those two specific Jsonnet files to the server
           specified by the current context in $KUBECONFIG.
        3. Both an environment name and a set of files. For example,
           `apply us-west/dev -f foo.jsonnet -f bar.jsonnet` would `apply`
           those two files to the cluster denoted by the `us-west/dev`
           environment.
      
      This "duality" remained in place primarily because it was important for
      the ksonnet CLI to maintain functional compatibility (though not strict
      CLI-level app compatibility) with the kubecfg tool.
      
      Some time ago the ksonnet CLI was forked from the kubecfg CLI, but it is
      only in this commit that we abandon this duality. Specifically, this
      commit will _require_ the environment name for all commands. For
      example, the form of `apply` will now be:
      `apply <env-name> [-f <file>]`.
      
      There are main parts to this:
      
        1. Refactoring core abstractions that supports this "duality".
           Specifically, removing the `cmd.envSpec` type and several
           functions, such as `cmd.parseEnvCmd`.
        2. Updating the tests to reflect this new directory structure.
      Signed-off-by: default avatarJessica Yuen <im.jessicayuen@gmail.com>
      4923a3f5
  2. 28 Nov, 2017 1 commit
  3. 22 Nov, 2017 1 commit
    • Jessica Yuen's avatar
      Improve logging for init · 97631513
      Jessica Yuen authored
      - Add message:  Creating a new app 'foo' at path '/path/to/foo'
      - On success, add message:  ksonnet app successfully created! Next, try
        creating a component with `ks generate`
      - On failure, provide suggestions for the user.
      - Make note that the context is retrieved from the kubeconfig file at
        the environment variable $KUBECONFIG
      97631513
  4. 21 Nov, 2017 1 commit
    • Alex Clemmer's avatar
      Fix `nil` dereference error in #129 · 7cd60cc1
      Alex Clemmer authored
      In line 161 of `root.go`, we're failing to check whether a cluster in
      the $KUBECONFIG clusters array exists before using it. This will cause a
      `nil` dereference error.
      7cd60cc1
  5. 15 Nov, 2017 2 commits
  6. 13 Nov, 2017 1 commit
    • Jessica Yuen's avatar
      Provide access to ExtCodes when the '-f' flag is provided · c97220f4
      Jessica Yuen authored
      Currently, ExtCodes are only provided when the 'env' flag is present in
      commands. The result is errors occuring when we run commands such as `ks
      show default -f components/guestbook-ui.jsonnet`, where the params
      ExtVar is needed. This commit fixes that scenario.
      c97220f4
  7. 08 Nov, 2017 3 commits
    • Jessica Yuen's avatar
      Jsonnet handling of component names with special characters · ce2d567d
      Jessica Yuen authored
      Currently, if a component name contains a special character, ex:
      foo-bar, this translates to the jsonnet identifier: foo-bar, which is
      invalid syntax.
      
      This change will quote component names where there are special
      characters.
      ce2d567d
    • Alex Clemmer's avatar
      Add `vendor/` to Jsonnet paths · 5327cf5c
      Alex Clemmer authored
      This resolves the first half of #68. When we `generate` using a
      prototype from a vendored dependency, it often results in a compilation
      error when we `apply`, because these prototypes usually depend on code
      that exists in the dependency, and `vendor/` is not a part of the
      Jsonnet search path.
      
      This commit resolves this problem by adding it to the search path.
      5327cf5c
    • Jessica Yuen's avatar
      Pass overrides by reference when initiating client · beddf415
      Jessica Yuen authored
      This fixes the bug where objects weren't being deployed to the cluster
      specified by the environment. This bug occurred because overrides (ex:
      cluster, namespace) were being lost because we weren't applying the
      changes to the correct override object. To fix this, we needed to pass
      the overrides by reference.
      beddf415
  8. 31 Oct, 2017 1 commit
    • Jessica Yuen's avatar
      Expand environment params.libsonnet · d55fbed6
      Jessica Yuen authored
      Expose the import path to environments/:env/params.libsonnet as an
      ExtCode so that it is made accessible to component files during
      expansion.
      d55fbed6
  9. 26 Oct, 2017 2 commits
    • Jessica Yuen's avatar
      Rename environment uri references to server · 3c9e07e9
      Jessica Yuen authored
      'server' is consistent with what is used by clientgo. 'uri' only
      introduces new language to ksonnet with the same meaning.
      3c9e07e9
    • Jessica Yuen's avatar
      Support `diff` between two environments · 2687c6d8
      Jessica Yuen authored
      This change enables the user to diff between two environments that are
      either local or remote.
      
      i.e.,
      
      `kubecfg diff local:dev local:prod` will diff between the expanded
      templates for each environment on disk.
      
      `kubecfg diff remote:dev remote:prod` will diff between two remote
      environment clusters. It does this by first expanding the component
      templates of each environment. Then, the live objects are fetched from
      each of the clusters and the diff is performed against the live objects.
      
      `kubecfg diff local:dev remote:prod` is also an option. This will diff
      between the expanded templates for 'dev' on disk and the live objects
      on 'prod's server.
      2687c6d8
  10. 25 Oct, 2017 2 commits
    • Jessica Yuen's avatar
      Set env namespace to default when namespace not provided · 209a5abf
      Jessica Yuen authored
      `ks env set foo --namespace=""` and `ks env add foo` will both set the
      namespace to 'default' in the environment's spec.json file.
      209a5abf
    • Jessica Yuen's avatar
      Init env metadata from provided context · e3e35d30
      Jessica Yuen authored
      `ks env add myenv --context=dev` will initialize the environment URI
      and namespace based on the context `dev`, as specfied in the
      kubeconfig file. The same applies for `ks init foo --context=dev`.
      
      If both the context and uri argument is not provided, the current
      context is used.
      
      This change will also remove uri as a mandatory arg in `ks env add`.
      The uri will be moved to a flag. It cannot be used at the same time as
      `context`.
      e3e35d30
  11. 17 Oct, 2017 3 commits
  12. 06 Oct, 2017 2 commits
    • Jessica Yuen's avatar
      Expand environment .jsonnet file · 6378e75a
      Jessica Yuen authored
      Commands that take `env` as a param currently expand all files in the
      `components` directory. This is no longer necessary with the
      introduction of `base.libsonnet` and the per-environment override
      `<env>.jsonnet` file.
      
      This commit will simply expand the single `<env>.jsonnet` file (which
      will implicitly expand all component files). The case of running
      `ksonnet apply default`, is equivalent to running `ksonnet apply -f
      environments/default/default.jsonnet`.
      6378e75a
    • Jessica Yuen's avatar
      Generate base.libsonnet in environments/ · 4b50beb8
      Jessica Yuen authored
      base.libsonnet is a generated file that exists at the root of the
      environments directory. This file is generated for all ksonnet projects.
      The main goal of this file is to import all components in the components
      directory, so that environments are able to easily extend / override any
      one of these components in a modular structure.
      4b50beb8
  13. 05 Oct, 2017 1 commit
    • Jessica Yuen's avatar
      Remove unnecessary param from defaultNamespace() · c95cde93
      Jessica Yuen authored
      The `clientConfig` param currently being passed is not needed, because
      it exists as a package level var in root. It also makes little sense to
      pass a custom `clientConfig` because if `overrides.Context.Namespace` is
      populated, the namespace that is returned is configured as an override
      in the package level `clientConfig` and not the `clientConfig` in the
      param.
      c95cde93
  14. 03 Oct, 2017 1 commit
    • Jessica Yuen's avatar
      Construct base components object · c97498df
      Jessica Yuen authored
      In order to support environment heirarchy, we need to be able to
      reference all components. This commit will implement component imports
      as k-v pairs ex: foo: "import/foo.jsonnet" as a Jsonnet object. This
      jsonnet object will then be assigned as an ExtCode so that it can be
      referenced by a base.libsonnet file which environments can build /
      override upon.
      c97498df
  15. 27 Sep, 2017 1 commit
  16. 21 Sep, 2017 4 commits
    • Alex Clemmer's avatar
      Remove client-go flags from commands that don't use them · f9723645
      Alex Clemmer authored
      Fixes #108.
      f9723645
    • Alex Clemmer's avatar
      Fix improper elision of -J flags · 4509a351
      Alex Clemmer authored
      Currently if we use a command like `apply default -f
      components/whatever.yaml`, kubecfg will fail to emit flags that add
      ksonnet-lib to the -J paths. This means that, while a command like
      `apply default` will correctly linke against (e.g.) `k.libsonnet`,
      adding the `-f` flag will not.
      
      This commit will correct this problem for all commands of this form.
      4509a351
    • Jessica Yuen's avatar
      Commands using the <env> arg should deploy to the correct cluster · 13f89a92
      Jessica Yuen authored
      For example, 'apply <env' currently operates as a no-op. With the
      introduction of simple environments in PR #131, 'apply <env>' should
      perform basic validation such that:
      
      1. The user has added the environment that is being deployed against to
      their Ksonnet project.
      
      2. The URI in the environment's spec file that the user wishes to deploy
      to should correspond to at least one cluster location as listed in
      kubeconfig.
      
      If either of those conditions are not satisfied, the kubecfg user will
      receive the corresponding error.
      
      In addition, this commit will set the kubectl --cluster flag to point at
      the cluster listed by the environment URI.
      13f89a92
    • Jessica Yuen's avatar
      Make Files and Environment not be mutually exclusive · 184756d8
      Jessica Yuen authored
      Currently, commands take either an <env> or a '-f' argument but not
      both. With this commit, we are allowing both args to be provided. The
      behavior is expand the files passed by the '-f' flag and deploy the
      objects to <env>.
      184756d8
  17. 19 Sep, 2017 1 commit
    • Jessica Yuen's avatar
      Set default log level to 'Info' · 3ca68ad8
      Jessica Yuen authored
      Currently 'Info' level logs are only shown with the '-v' flag. This
      makes commands without the '-v' flag of little use to users, especially
      on success cases, due to no output.
      
      This commit will set the default log level to 'Info', and passing a '-v'
      flag will log at a 'Debug' level.
      3ca68ad8
  18. 18 Sep, 2017 1 commit
    • Jessica Yuen's avatar
      Add subcommand 'env set' · f86667a6
      Jessica Yuen authored
      'env set <name>' sets environment fields such as the name, and cluster
      URI. It currently accepts the flags '--name' and '--uri'. Changing the
      name of an environment will also update the directory structure in
      'environments'.
      f86667a6
  19. 08 Sep, 2017 1 commit
    • Jessica Yuen's avatar
      Change directory structure generated by 'init' to support envs · 1e656f24
      Jessica Yuen authored
      This commit will remove the vendor/lib and vendor/schema directories
      generated by 'init'. An 'environments' directory will be created from
      the root app directory, with the default environment directory 'dev'
      and it's containing contents rooted at 'environments'.
      
      The intention of environments are to represent the deployment
      environments of Kubernete clusters, with the following example
      directory structure:
      
      app-name/
        ..
        envs/
          dev/
          us-west/
            prod/
            staging/
      1e656f24
  20. 07 Sep, 2017 2 commits
    • Alex Clemmer's avatar
      Deprecate `update` subcommand; introduce `apply` · 94a18089
      Alex Clemmer authored
      This commit is a follow-up to the discussion in the ksonnet.next design
      doc, in which users consistently expressed their preference that the
      `update` command be called `apply`.
      
      NOTE: We have renamed `pkg/kubecfg/update_test.go` ->
      `pkg/kubecfg/apply_test.go`, but we copy the `update`'s integration test
      file. The reason is that the `update` unit tests actually test things
      like GC (rather than the command itself), so the file name is
      inconsequential. On the other hand, the integration tests test the
      commands themselves, so it is important to have two copies, one for
      `update` and one for `apply`.
      94a18089
    • Alex Clemmer's avatar
      Include `lib/` and `vendor/lib` when expanding templates · bc77be8e
      Alex Clemmer authored
      Currently, if the user wants to deploy a ksonnet application, and that
      application uses some vendored library, or something in the `lib/`
      directory, they will have to pass the appropriate `-J` flags into the
      command themselves.
      
      This commit will automatically add these whenever we're in an app
      directory and a command is issued. In particular, even if the user
      passes in the `-f` flag (rather than an environment name), we'll still
      add library paths to the command if we're in a ksonnet app directory.
      This is meant to capture the case that a user wants to update one
      resource in particular in a ksonnet application.
      bc77be8e
  21. 06 Sep, 2017 1 commit
  22. 05 Sep, 2017 1 commit
  23. 02 Sep, 2017 2 commits
  24. 01 Sep, 2017 1 commit
    • Jessica Yuen's avatar
      Refactor cmd/ application logic to pkg/ · f7d6436d
      Jessica Yuen authored
      This commit will separate the application level logic for the 'show', 'delete',
      'validate', and 'diff' commands from the Cobra logic in the cmd/ package.  The
      application level logic will be placed in pkg/kubecfg/.
      f7d6436d
  25. 30 Aug, 2017 2 commits
    • Alex Clemmer's avatar
      Make delete, diff, show, update, and validate aware of ksonnet apps · af3f0f6c
      Alex Clemmer authored
      The ksonnet.next design doc specifies the core kubecfg verbs (i.e., the
      ones listed above) to all have the form:
      
        kubecfg <verb> [<env-name>|-f <file-or-dir>]
      
      That is to say, each of these should be able to take either an
      environment name, or a `-f` flag with a list of files and directories to
      apply `verb` on. In the case of the environment, we will apply `verb` to
      every component in the `components/` directory.
      
      This commit implements this behavior for all these verbs.
      af3f0f6c
    • Alex Clemmer's avatar
      Add a template expander abstraction · 86c5ad02
      Alex Clemmer authored
      This commit will introduce the `template.Expander` abstraction, which is
      meant to abstract over an invocation of the Jsonnet VM. Specifically, it
      provides facilities for users to provide (e.g.) Jpaths, ext vars, and so
      on.
      
      The main justification for this change is:
      
      * We need a common way for the `pkg` and `cmd` packages to interact with
        the Jsonnet VM.
      * The `utils` package is already too much of a catch-all.
      * It's easier to think about an invocation of the Jsonnet VM when we
        additionally encapsulate the parameters we pass to it on every
        invocation in kubecfg.
      86c5ad02
  26. 08 Aug, 2017 1 commit