Skip to content

Commit

Permalink
Revert "Remove docs for Strict Mode and --strict flag (#210)" (#241)
Browse files Browse the repository at this point in the history
This reverts commit d7b989a.
  • Loading branch information
jonjohnsonjr authored Nov 4, 2020
1 parent 79beb3b commit f7efca3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ of convenience for cleaning up resources created through `ko apply`.
`ko version` prints version of ko. For not released binaries it will print hash
of latest commit in current git tree.

### Strict Mode

It can be difficult for `ko` to determine whether a string in a YAML file is
intended to be an import path, due to typos, non-`package main` packages, and
conflicts between import paths and common strings (e.g., a package whose import
path is `busybox`). To solve this, `ko` supports "Strict Mode".

When referencing an import path in the YAML file, prefix the string with the
string `ko://` (e.g., `ko://github.com/my/repo/cmd/foo`). Then, when calling
`ko apply` or `ko resolve`, pass `--strict`. If a string with the `ko://` prefix
is not determined to be a valid import path, the command will fail, rather than
passing it through to the resolved YAML.

## With `minikube`

You can use `ko` with `minikube` via a Docker Registry, but this involves
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func addApply(topLevel *cobra.Command) {
options.AddPublishArg(apply, po)
options.AddFileArg(apply, fo)
options.AddSelectorArg(apply, so)
options.AddStrictArg(apply, sto)
options.AddBuildOptions(apply, bo)

// Collect the ko-specific apply flags before registering the kubectl global
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func addCreate(topLevel *cobra.Command) {
options.AddPublishArg(create, po)
options.AddFileArg(create, fo)
options.AddSelectorArg(create, so)
options.AddStrictArg(create, sto)
options.AddBuildOptions(create, bo)

// Collect the ko-specific apply flags before registering the kubectl global
Expand Down
9 changes: 9 additions & 0 deletions pkg/commands/options/strict.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@

package options

import (
"github.com/spf13/cobra"
)

// StrictOptions holds options to require strict references.
type StrictOptions struct {
Strict bool
}

func AddStrictArg(cmd *cobra.Command, so *StrictOptions) {
cmd.Flags().BoolVarP(&so.Strict, "strict", "", so.Strict,
`If true, require package references to be explicitly prefixed with "ko://"`)
}
1 change: 1 addition & 0 deletions pkg/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func addResolve(topLevel *cobra.Command) {
options.AddPublishArg(resolve, po)
options.AddFileArg(resolve, fo)
options.AddSelectorArg(resolve, so)
options.AddStrictArg(resolve, sto)
options.AddBuildOptions(resolve, bo)
topLevel.AddCommand(resolve)
}

0 comments on commit f7efca3

Please sign in to comment.