Skip to content

Commit

Permalink
pipelines update
Browse files Browse the repository at this point in the history
  • Loading branch information
lkingland committed Apr 9, 2024
1 parent c6bafaf commit 89bd283
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 190 deletions.
15 changes: 2 additions & 13 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ import (
// These are the minimum settings necessary to create the default client
// instance which has most subsystems initialized.
type ClientConfig struct {
// PipelinesNamespace in the remote cluster to use for any client commands which
// touch the remote. Optional. Empty namespace indicates the namespace
// currently configured in the client's connection should be used.
//
// DEPRECATED: This is being removed. Individual commands should use
// either a supplied --namespace flag, the current active k8s context,
// the global default (if defined) or the static default "default", in
// that order.
PipelinesNamespace string

// Verbose logging. By default, logging output is kept to the bare minimum.
// Use this flag to configure verbose logging throughout.
Verbose bool
Expand Down Expand Up @@ -68,7 +58,7 @@ func NewClient(cfg ClientConfig, options ...fn.Option) (*fn.Client, func()) {
t = newTransport(cfg.InsecureSkipVerify) // may provide a custom impl which proxies
c = newCredentialsProvider(config.Dir(), t) // for accessing registries
d = newKnativeDeployer(cfg.Verbose)
pp = newTektonPipelinesProvider(cfg.PipelinesNamespace, c, cfg.Verbose)
pp = newTektonPipelinesProvider(c, cfg.Verbose)
o = []fn.Option{ // standard (shared) options for all commands
fn.WithVerbose(cfg.Verbose),
fn.WithTransport(t),
Expand Down Expand Up @@ -122,9 +112,8 @@ func newCredentialsProvider(configPath string, t http.RoundTripper) docker.Crede
return creds.NewCredentialsProvider(configPath, options...)
}

func newTektonPipelinesProvider(namespace string, creds docker.CredentialsProvider, verbose bool) *tekton.PipelinesProvider {
func newTektonPipelinesProvider(creds docker.CredentialsProvider, verbose bool) *tekton.PipelinesProvider {
options := []tekton.Opt{
tekton.WithNamespace(namespace),
tekton.WithCredentialsProvider(creds),
tekton.WithVerbose(verbose),
tekton.WithPipelineDecorator(deployDecorator{}),
Expand Down
22 changes: 2 additions & 20 deletions cmd/config_git_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewConfigGitRemoveCmd(newClient ClientFactory) *cobra.Command {
such as local generated Pipelines resources and any resources generated on the cluster.
`,
SuggestFor: []string{"rem", "rmeove", "del", "dle"},
PreRunE: bindEnv("path", "namespace", "delete-local", "delete-cluster"),
PreRunE: bindEnv("path", "delete-local", "delete-cluster"),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return runConfigGitRemoveCmd(cmd, newClient)
},
Expand All @@ -37,20 +37,6 @@ func NewConfigGitRemoveCmd(newClient ClientFactory) *cobra.Command {
fmt.Fprintf(cmd.OutOrStdout(), "error loading config at '%v'. %v\n", config.File(), err)
}

// Function Context
f, _ := fn.NewFunction(effectivePath())
if f.Initialized() {
cfg = cfg.Apply(f)
}

// Flags
//
// Globally-Configurable Flags:
// Options whose value may be defined globally may also exist on the
// contextually relevant function; but sets are flattened via cfg.Apply(f)
cmd.Flags().StringP("namespace", "n", cfg.Namespace,
"Deploy into a specific namespace. Will use function's current namespace by default if already deployed, and the currently active namespace if it can be determined. ($FUNC_NAMESPACE)")

// Resources generated related Flags:
cmd.Flags().Bool("delete-local", false, "Delete local resources (pipeline templates).")
cmd.Flags().Bool("delete-cluster", false, "Delete cluster resources (credentials and config on the cluster).")
Expand All @@ -69,8 +55,6 @@ type configGitRemoveConfig struct {
// working directory of the process.
Path string

PipelinesNamespace string

// informs whether any specific flag for deleting only a subset of resources has been set
flagSet bool

Expand All @@ -93,8 +77,6 @@ func newConfigGitRemoveConfig(_ *cobra.Command) (c configGitRemoveConfig) {
}

c = configGitRemoveConfig{
PipelinesNamespace: viper.GetString("namespace"),

flagSet: flagSet,

metadata: pipelines.PacMetadata{
Expand Down Expand Up @@ -181,7 +163,7 @@ func runConfigGitRemoveCmd(cmd *cobra.Command, newClient ClientFactory) (err err
return
}

client, done := newClient(ClientConfig{PipelinesNamespace: cfg.PipelinesNamespace, Verbose: cfg.Verbose})
client, done := newClient(ClientConfig{Verbose: cfg.Verbose})
defer done()

return client.RemovePAC(cmd.Context(), f, cfg.metadata)
Expand Down
9 changes: 3 additions & 6 deletions cmd/config_git_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewConfigGitSetCmd(newClient ClientFactory) *cobra.Command {
directory or from the directory specified with --path.
`,
SuggestFor: []string{"add", "ad", "update", "create", "insert", "append"},
PreRunE: bindEnv("path", "builder", "builder-image", "image", "registry", "namespace", "git-provider", "git-url", "git-branch", "git-dir", "gh-access-token", "config-local", "config-cluster", "config-remote"),
PreRunE: bindEnv("path", "builder", "builder-image", "image", "registry", "git-provider", "git-url", "git-branch", "git-dir", "gh-access-token", "config-local", "config-cluster", "config-remote"),
RunE: func(cmd *cobra.Command, args []string) (err error) {
return runConfigGitSetCmd(cmd, newClient)
},
Expand Down Expand Up @@ -93,8 +93,6 @@ func NewConfigGitSetCmd(newClient ClientFactory) *cobra.Command {
type configGitSetConfig struct {
buildConfig // further embeds config.Global

PipelinesNamespace string

GitProvider string
GitURL string
GitRevision string
Expand Down Expand Up @@ -126,8 +124,7 @@ func newConfigGitSetConfig(_ *cobra.Command) (c configGitSetConfig) {
}

c = configGitSetConfig{
buildConfig: newBuildConfig(),
PipelinesNamespace: viper.GetString("namespace"),
buildConfig: newBuildConfig(),

GitURL: viper.GetString("git-url"),
GitRevision: viper.GetString("git-branch"),
Expand Down Expand Up @@ -307,7 +304,7 @@ func runConfigGitSetCmd(cmd *cobra.Command, newClient ClientFactory) (err error)
return
}

client, done := newClient(ClientConfig{PipelinesNamespace: cfg.PipelinesNamespace, Verbose: cfg.Verbose}, fn.WithRegistry(cfg.Registry))
client, done := newClient(ClientConfig{Verbose: cfg.Verbose}, fn.WithRegistry(cfg.Registry))
defer done()

return client.ConfigurePAC(cmd.Context(), f, cfg.metadata)
Expand Down
4 changes: 3 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,14 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {

// Deploy
if cfg.Remote {
var url string
// Invoke a remote build/push/deploy pipeline
// Returned is the function with fields like Registry, f.Deploy.Image &
// f.Deploy.Namespace populated.
if f, err = client.RunPipeline(cmd.Context(), f); err != nil {
if url, f, err = client.RunPipeline(cmd.Context(), f); err != nil {
return
}
fmt.Fprintf(cmd.OutOrStdout(), "Function Deployed at %v\n", url)
} else {
var buildOptions []fn.BuildOption
if buildOptions, err = cfg.buildOptions(); err != nil {
Expand Down
12 changes: 7 additions & 5 deletions pkg/functions/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,10 @@ func (c *Client) Deploy(ctx context.Context, f Function, oo ...DeployOption) (Fu

// RunPipeline runs a Pipeline to build and deploy the function.
// Returned function contains applicable registry and deployed image name.
func (c *Client) RunPipeline(ctx context.Context, f Function) (Function, error) {
// String is the default route.
func (c *Client) RunPipeline(ctx context.Context, f Function) (string, Function, error) {
var err error
var url string
// Default function registry to the client's global registry
if f.Registry == "" {
f.Registry = c.registry
Expand All @@ -827,16 +829,16 @@ func (c *Client) RunPipeline(ctx context.Context, f Function) (Function, error)
} else if f.Deploy.Image == "" {
f.Deploy.Image, err = f.ImageName()
if err != nil {
return f, err
return "", f, err
}
}

// Build and deploy function using Pipeline
_, f.Deploy.Namespace, err = c.pipelinesProvider.Run(ctx, f)
url, f.Deploy.Namespace, err = c.pipelinesProvider.Run(ctx, f)
if err != nil {
return f, fmt.Errorf("failed to run pipeline: %w", err)
return url, f, fmt.Errorf("failed to run pipeline: %w", err)
}
return f, nil
return url, f, nil
}

// ConfigurePAC generates Pipeline resources on the local filesystem,
Expand Down
6 changes: 3 additions & 3 deletions pkg/functions/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ func TestClient_Pipelines_Deploy_Image(t *testing.T) {
}

// Upon pipeline run, the .Deploy.Image should be populated
if f, err = client.RunPipeline(context.Background(), f); err != nil {
if _, f, err = client.RunPipeline(context.Background(), f); err != nil {
t.Fatal(err)
}
expected := "example.com/alice/myfunc:latest"
Expand All @@ -1409,7 +1409,7 @@ func TestClient_Pipelines_Deploy_Image(t *testing.T) {
t.Fatal(err)
}
// Upon pipeline run, the function should be populated;
if f, err = client.RunPipeline(context.Background(), f); err != nil {
if _, f, err = client.RunPipeline(context.Background(), f); err != nil {
t.Fatal(err)
}
expected = "registry2.example.com/bob/myfunc:latest"
Expand Down Expand Up @@ -1461,7 +1461,7 @@ func TestClient_Pipelines_Deploy_Namespace(t *testing.T) {
t.Fatal(err)
}

if f, err = client.RunPipeline(context.Background(), f); err != nil {
if _, f, err = client.RunPipeline(context.Background(), f); err != nil {
t.Fatal(err)
}

Expand Down
1 change: 0 additions & 1 deletion pkg/pipelines/tekton/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func TestGitlab(t *testing.T) {
}
pp := tekton.NewPipelinesProvider(
tekton.WithCredentialsProvider(credentialsProvider),
tekton.WithNamespace(ns),
tekton.WithPacURLCallback(func() (string, error) {
return "http://" + pacCtrHostname, nil
}))
Expand Down
Loading

0 comments on commit 89bd283

Please sign in to comment.