Commit Graph

21 Commits

Author SHA1 Message Date
Luke Kingland e0c4d7bf91
cleanup unused args (#2240) 2024-03-25 08:02:00 +00:00
Luke Kingland 4e0db21b34
rename knative-sandbox (#1905)
* rename knative-sandbox

* fixup bad merge

* fixup: use knative.dev not github.com import path

---------

Co-authored-by: Matej Vasek <mvasek@redhat.com>
Co-authored-by: Matej Vasek <matejvasek@gmail.com>
2023-08-05 02:11:08 +00:00
Luke Kingland aa582dad21
cli help text updates and flags cleanup (#1564)
* cli help text and flags cleanup

- verbose flag uses global setting throughout
- confirm flag added using shared visitor throughout
- path flag added using shared visitor throughout
- removes --version flag on root as redundant with subcommand
- splits main help's 'Main Commands' into 'Primary Commands' and 'Development
  Commands' groups
- Moves RunE definition into flag struct literals

* remove commented code
2023-03-01 09:35:54 +00:00
Luke Kingland 3624ccb58d
command aliases (#1578)
Ensures commands which have subcommands to operate on individual members
(list, add, remove etc) have singular and plural as aliases.

Ensures consistent usage of linux-command-style aliases for list,remove
and rename operations: "ls", "rm", "mv"
2023-02-23 14:07:29 +00:00
Lance Ball 44bb13f803
feat: adds refspec support for `func repo add` (#1558)
* add option 'branch' to command 'repository add'

* Format go code (#1407)

Signed-off-by: Knative Automation <automation@knative.team>

* chore: refactor repository layout (#1554)

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>

* fixup: removes --branch tag from repo commands

Removes the currently in-flight work on the `--branch` tag, simply
supporting a `refspec` on the repository URI. For example,
https://github.com/knative-sandbox/func-tastic#metacontroller will pull
the `func-tastic` repo, and set the currently active HEAD to the
`metacontroller` branch. Adds support for displaying this with the
command `func repo list -v`.

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: add example to `func repo add` documentation

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: adjust test output expectations

Signed-off-by: Lance Ball <lball@redhat.com>

---------

Signed-off-by: Knative Automation <automation@knative.team>
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
Signed-off-by: Lance Ball <lball@redhat.com>
Co-authored-by: Yingchun Guo <yingchun.guo@intel.com>
Co-authored-by: knative-automation <automation@knative.team>
Co-authored-by: Zbynek Roubalik <zroubalik@gmail.com>
2023-02-16 04:05:51 +00:00
Zbynek Roubalik 5a4803bf95
chore: refactor repository layout (#1554)
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
2023-02-15 08:46:52 +00:00
Adam Boczek 2f021f118b
chore: refactor commands help to use templates (#1485)
* chore: extend help template engine and docs generator to get root use

* chore: refactor deploy cmd

* chore: refactor build cmd

* chore: refactor all relevant commands and remove defaultTemplatedHelp func

* chore: update docs

* chore: remove unused functions

* chore: add template func for rendering sub-templates

* chore: fix for typos
2023-01-16 20:40:53 +00:00
Luke Kingland 0fa9359750
feat: namespace globally configurable (#1352)
* namespace global config

* integrate namespace config into commands

* comment updates

* combine config write tests

* updates per code review

* regen docs
2022-10-31 18:07:12 +00:00
Luke Kingland 034e2de849
chore: global config file paths (#1344)
* feat: config members and paths

- Adds Builder, Namespace, Registry and Verbose as globally
  configurable.
- Fixes problems where file paths were being created or required when
  not necessary.
- Relocates environment variable usage to main's use of config
- Adds FUNC_CONFIG_PATH
- Only creates paths on disk when necessary
- Makes non-existent config paths nonfatal

* postpone adding some members
2022-10-21 10:38:13 +00:00
Lance Ball 5adec03c7b
chore: update all references to kn-plugin-func (#1311)
* chore: update all references to kn-plugin-func

I did not change references in CHANGELOG.md but otherwise, I believe
this should cover all configuration settings, image names, package
names, etc.

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: fix instances_test.go

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: still some stray kn-plugin-func

Signed-off-by: Lance Ball <lball@redhat.com>

Signed-off-by: Lance Ball <lball@redhat.com>
2022-10-13 16:31:53 +00:00
Luke Kingland 4c8f730099
feat: readonly global config (#1260)
* improved deploy test output

* remove unused config struct

* feat: read-only global config

Co-authored-by: Lance Ball <lball@redhat.com>
2022-09-23 17:49:13 +00:00
David Fridrich e659256005
chore: use lower case *functions* in all CLI outputs (#1135)
* first run, F -> f

* fix

* fix

* misspells

* client*.go files

* add client*.go: misspells

* cmd dir test files

* docker dir

* function* files

* i*.go and job.go

* job.go,mock dir,repos*,s2i dir,schema dir,templates*

* test dir

* testing dir

* root dir *.go second round
2022-07-27 13:34:36 +00:00
Luke Kingland 9a0335de7d
src: exported client constructor with options (#883)
* update root and version structure and help text

* fix: limit openshift int test with tag

* refactor: commands to use simplifed, unified constructor

* fix ineffectual assignment lint error

* cleanup

* add repository to run command

* callout for forthcoming s2i builder impl

* lint errors

* re-add the deferred client factory

* remove setNamespaceFlag now that it is persistent

* avoid side-effect of global-mutating deploy tests

* reduce line-by-line difference for PR ease

* simplificaiton of tests and comment lines for further PR ease purposes

* reduce inconsequential differences for ease of PR

* tests to RootCommandConfig

* review comment updates

* fix lint errors

* replace stdlib Setenv in tests

Using t.Setenv will require an update to go1.17, which is out of scope
for this PR.

* pass ClientFactory throughout

* explicitly empty test command args

See https://github.com/spf13/cobra/pull/155

Errors can still be encountered when, for example, using precomiled
tests.  Explicitly setting constructed command args to the empty slice
ensures we avoid hitting any futher edge cases.
2022-03-30 00:58:46 +00:00
Luke Kingland 9dec4c20ee
differentiate repository and repositories (#900) 2022-03-16 14:01:59 -07:00
Luke Kingland 2bd5254f19
feat: command help text template preprocessing (#875) 2022-03-02 03:56:43 -08:00
Matej Vasek abd4eea0c7
Cleanup commands (#807)
* src: refactor commands

Commands are constructed from root,
not by using init() blocks.

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup the prefix issue

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup style

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* fixup nolint:misspell

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2022-02-03 10:26:21 -08:00
Luke Kingland db9ad07c70
feat: ensure config and repos path exists (#683) 2021-11-29 13:53:08 -08:00
Lance Ball e319ea3b62
feat: add support for manifest.yaml at repo/language/template levels (#558)
* feat!: add support for manifest.yaml and runtime.yaml

BREAKING CHANGE
This commit adds the concepts of a manifest.yaml file at the top level
of a template repository, and a runtime.yaml file for each language/runtime
within the repository. Prior to this, repository metadata was primarily
restricted to information that could be gleaned from the file system, such
as the directory name used as the Name.

A manifest.yaml file contains a Name, URL, Version, and a list of supported
runtimes; and if all of the runtimes expose the same health endpoints, these
can be set here.

Within a runtime directory, there may exist a runtime.yaml file which allows
language pack providers to set the health endpoints, overriding the values
set in manifest.yaml, as well as Builders and Buildpacks.

This change removes support for a builders.yaml file in a runtime/template
directory, as this was guaranteed to be redundant with the builders.yaml
file in a sibling template directory. The choice was to move these up a
level to runtime/runtime.yaml.

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: bump go version for unit tests

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: using go 1.16 now requires 'go mod tidy'
See: https://golang.org/doc/go1.16

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: restore support for directory traversal

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: whitespace linting

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update func_yaml-schema.json

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: spelling errors caught by reviewdog

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: use os.ReadDir

Signed-off-by: Lance Ball <lball@redhat.com>

* squash: restore project creation from remote repos

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove billyFilesystem

Signed-off-by: Lance Ball <lball@redhat.com>

* doc: expand on language pack documentation

Adds more detail around how language packs can be provided by third
parties, and the expected structure and metadata required.

Fixes: https://github.com/knative-sandbox/kn-plugin-func/issues/452

Signed-off-by: Lance Ball <lball@redhat.com>

* doc: update language pack documentation

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: cleanup deps

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: cleanup deps - again

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: reviewdog whitespace cleanup

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: custom repo template listing

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: bump go version for integration tests

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: adjust test-templates repo uri for e2e

Signed-off-by: Lance Ball <lball@redhat.com>

* fix: don't fail when extended templates don't support a given runtime

Signed-off-by: Lance Ball <lball@redhat.com>

* src: repo and template type hierarchy

As the client API increases in complexity, upgrading to a more correct
type hierarchy for the object managers serves to keep things clean.  In
this update, the Repository and Templates manager now use constructors
with private members, including a backreference to the root Client
object, which provides the mangers with full access to the current
client instance API for implementing their (growing) features.

* src: template manager writes

The templateWriter struct has now been upgraded to integrate with the
newly-added type system which includes a Templates Manager by adding a
.Write method which writes a template at the given location.  This
encapsulation of the write functionality moves us towards having a
cleaner abstraction atop writing any template to disk from any
repository.

In addition, the "Get" prefix was removed from many accessor methods, as
this is standard a Go idiom.

* src: templates write including denormalize

- merges templateWriter into templates manager
- denormalization of builders, health endpoints etc. made part of .Write
- write logic now works on a Template rather than string paths etc

The templates manager can now write out a template given a function directy.
Included internnaly to write is the denormalization logic, which is now closer
to where it is used, which should improve cohesion and decouple the template
implementation detail from the Client. Also moves the write logic closer to the
template itself, with the expectation the same will happen for functions when
Config and Function are merged.

* src: vendor

* src: merge manifests into domain model

In general, the manifests sytsem is merged more tightly into the overall
system while also expalding it to use a path to templates to avoid
having to create a full filesystem shadow-copy in yaml. Preserves
backwards-compatiblity by keeping the base case a yaml-free repo of only
templates.  Creaets a hierarchical inheritance from repository to
runtime to template for builders, endpoints etc.  whcih allows for the
manifest within templates to be a first-class citizen, though its use
will be rather rare.  Some more in-depth explanations of the more
substantive changes are as follows:

- Merges Manifest with Repository

The Manifest structure is essentially a serialized Repository, so they
are now the same object.

- Converts repo URL to a calculated field

The URL is informative and entirely dependent on the current state of
the repo, so it should be calculated to avoid confusion and avoid being
serialized to the manifest.

- Merge FunctionTemplate with Template

The struct being serialized here is a Template, so they are now the same object

- Extracts new "BuildConfig" embedded struct

The Builders and Buildpacks members are shared between Repository,
Runtime and Template, so they are now an embedded stuct in the same
manner as HealthEndpoints.

- yaml 'inline' declaration for embedded structs

The HealthEndpoints and other embedded structs were not actually being
read from their configs because of a nuance of yaml which (in contrast
to json unmarshallers) requires the `,inline` tag on the struct member
to trigger inclusion in decode.

- Replaces Repository's runtimes member with templates

While it is true that on disk templates are subdivided into their
effective runtime, this is for ease of development.  The logical
structure is: repositories have templates.  Templates are applicabe to
runtimes.  Therefore the correct API is to have templates a direct
member of repository but requiring a runtime filter for access.

- Use repository templates path instead of full list

The goal is to support the use of repositories which contain more than
just templates.  The solution is to define an alternate location for
templates (such as ./templates).  Creating an entire exhaustive manifest
where each runtime and each template is defined with a name and path is
a usurpation of the responsibilities of a filesystem, and causes
unintend negative knock-on effects.  Let's try this simple solution
before jumping to the nuclear option of defining a filesystem-in-yaml.

- Use filesystems when loading repository objects

The fact that a file exists on the disk, embedded, or remote should be
of no concern to most of the code.  This is accomplished by using the
filesystem abstraction which is used during template writing.  This will
be further improved in future versions by upgrading to use the fs.FS
interface and tooling.

- Uses manifest.yaml at all levels

Once the hierarchical nature of the manifest was instituted, it seemed
more intuitive to have the same filename at each level.  This also has
the nice benefit of being backwards-compatible with template-level
manifest.  This is not a correctness issue, but a guess that remembering
a single filename which can exist at different levels in a hierarchy is
easier to remember than different filenames, and its location in the
hierearchy sufficient differentiator making the different filenames
_perhaps_ unencssary.  The constants are left as separate for an easy
revert.

- Moves static defaults into code wherever possible

Wherever yaml was being statically compiled in, it was updated such that
canonical values for static defaults were defined on the Go structure,
with the yaml being for overrides.  For example Default Readiness and
Liveness endpoints.

Some notable benefits of letting the filesystem do it's thing:
* Preserves the ability to create a repository of templates without
  hacking yaml
* Reflects changes directly in IDEs which have native support for
  filesystem, not so for a proprietary manifest.yaml
* the builtin repository has no name, so parsing a manifest from within
  it is both prone to error and confusing, as it could lead future
  developers to submit PRs which change its name.

* fix: revert repository.git to a bare server repo

* src: repository default name

The Repository struct now includes a Name and DefaultName. The former is
the current name of the repository, and corresponds to the path on disk.
The latter is the name specified in the manifest.yaml, and is used as
the default name of the repository when no name is provided.

Fixes an issue where there could be name collisions using a uuid for the
initial name until the manifest is read in.

Restructures the embedded repositories such that one exemplifies a base
case repo with no metadata and only templates, the other specifying a
manifest to exemplify for example a complete language pack.

Adds a test such that all three cases are covered: explicit name, no
name but manifest-defined default name, URI-derived name.

* feat: single repo mode

Enables single repository mode suystem-wide, which fully implements the
logic intended by the WithRepository option.

The default repoisitory is now programatically defined, and while by
default is the embedded repo, it can be overriden using the
WithRepository option.  This keeps the logic internal to the
repositories managet, removeing the need for a crossp-cutting concern in
other parts of the system.

* src: manifest inheritance and existence tests

Respects alternate templates location when defined in a manifest.
Respects manifest embedded structs HealthEndpoints and BuildConfig at
each of the three levels, with inheritance:  Repo, Runtime and Template.
Separates test repositories into the two cases of a templates-only repo
(with no manifest) and a complex repo (with manifests) such as for
language packs.
Leaves the BuildConfig struct as inline but sets the HealthEndpoints as
being named, such that the latter has its fields in the yaml under the
key 'healthEndpoints' but the former does not (passthrough).
Adds error checks when attempting to access named repo when in
single-repo mode.

* src: remove function merge

Removes feature of mergine a func.yaml defined in a template in favor of
sticking with the manifest.yaml until such time as this is requested.
Assuming YAGNI.

* src: repo filesystems

- Embeds repositories with an internal filesystem
- Replaces filesystem disk checkouts with in-memory until final write
- Combines template Write of various types into a single write which uses the
  filesystem of the applicable templates's repository
- Template is now a simple noun, with logic localized to the templates manager
- Adds better error message regarding single repo mode conditions

The reason for replacing filesystem-based repository instances with in-memory
(especially remote for WithRepository mode) is for a few reasons:  First, 'Add'
will fail without using the temporary UUID hack if there already exists a
repository of the _repo_ name (due to a filesystem collision).  We have
to read the repo to determine the default name as well, so it's messy to avoid.
Second, using an on-disk version is potentially leaky because it may leave
files on the system in the event of a process interruption; able to be
mitigated, but with a likewise hacky use of a os temp directory.  Third, it
may cause racing conditions when using multiple instances the Client as a lib.
Lastly, it precludes our ability to run without touching the filesystm: a
useful mode when running as a pure library or in security-restricted
environments.

* fix: paths within embedded fs

* src: repositories code cleanup

* Removes the manual 0_18 version suffix
* Reanames "single" (uri for single-mode) to the more descriptive
  "remote" (with associated accessor api)
* Default repo name when no URI provided is set to default
* Various wording improvements in error text and comments

* src: error formatting

* feat: templates from local file paths

Adds back the local os filesystem as a fallthrough to support loading
template repositories from file:// paths on disk, without the
requirement that they also be git repositories.

* fix: clone once

Fixes the shortcut of performing a clone to read the manifest prior to
cloning the repository to disk.  This double-clone was replaced by a
single clone (applying the manifest) followed by a file copy from the
in-memory FS to the on-disk repository location.

* src: test fixes

* respect explict name on repository .Add
* fail if repository already exists
* update expected test filenames to new general (non-go-specific) setup
* adds the default repo name to the NewRepository constructor,
  internalizing the somewhat tricky default logic.
* move repo write logig to repo itself, as it will contain impl-specific
  nuances.
* invalid repo path is an error, but only if defined
* temporarily disable repository URL test

* src: update templates test to reflect new name 'cloudevents'

* src: fix go templates and repackage

* fixup: reviewdog spelling errors

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: reviewdog whitespace cleanup

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: run ./hack/update-codegen.sh

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: restore boson-project templates for e2e

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: do not error if default repo location does not exist

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: typo

Signed-off-by: Lance Ball <lball@redhat.com>

* paketo builder and paket community rust buildpack (#599)

* fixup: apply f161d50084

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: update documentation to match impl

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: add git attributes to ignore linting on binary files

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: remove whitespace

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: tweak linter rules

Signed-off-by: Lance Ball <lball@redhat.com>

* fixup: tweak .gitattributes

Signed-off-by: Lance Ball <lball@redhat.com>

Co-authored-by: Luke Kingland <lkingland2038@gmail.com>
Co-authored-by: Shashankft9 <48708039+Shashankft9@users.noreply.github.com>
2021-10-27 07:09:01 -07:00
Luke Kingland 4fe9fdcab0
feat: create cli (#547)
* feat: create cli prompts

* feat: display effective runtimes in prompt

replaces the static list of supported runtimes with a dynamic list of
currently installed+available runtimes; called the effective runtimes.
Used for both prompting and validation.

* feat: dynamic create help and error text

Output from create help text and the create commands now show valid
options for both language runtimes and templates.

* feat: runtime tab completion for runtmes and templates

* feat: support FUNC_PARENT_COMMAND in help

* feat: confirmation of successful create

* fix: include name in initial creation

* src: remove unnecessary comments on create name

* fix: associate prompt questions with struct members in create

* e2e: update tests for language flag

* fix: support nonexistent repositories path

Listing installed repositories considers a missing path equivalent to a
lack of installed repositories.  This will change to an error when the
logic to determin default config directory, and automatically create
initial structure, is moved into the client library.

* fix: only CLI-validate when no repo override
2021-09-22 13:00:12 -07:00
Luke Kingland 90c60b693d
fix: removal of repositories (#524) 2021-09-15 06:48:08 -07:00
Luke Kingland ae638c349c
feat: repository management cli (#514)
* feat: repository management cli

* src: cleanup imports, newlines, spelling and trailing whitespace
2021-09-09 08:09:00 -07:00