Skip to content

Commit

Permalink
Cleanup orphaned func, new image-name calculation (#1962)
Browse files Browse the repository at this point in the history
* forced namespace change, deletes old func, kind works

Signed-off-by: gauron99 <[email protected]>

* new .deploy.image field

Signed-off-by: gauron99 <[email protected]>

* building

* building

* add first iteration of complete functionality with f.Build.Image and f.Deploy.Image that STILL contains a workaround for image digest which is populated on Push instead of Build

Signed-off-by: gauron99 <[email protected]>

* base tests fixes for compile

Signed-off-by: gauron99 <[email protected]>

* fix base tests2 for now, integration test has a possible TODO

Signed-off-by: gauron99 <[email protected]>

* new generated schema

Signed-off-by: gauron99 <[email protected]>

* fix some tests using .Image and create new test

Signed-off-by: gauron99 <[email protected]>

* remove nested .func

Signed-off-by: gauron99 <[email protected]>

* get rid of test

Signed-off-by: gauron99 <[email protected]>

* remove my debug test

* fix namespace change test

Signed-off-by: gauron99 <[email protected]>

* fix pipeline run to use .Deploy.Image

Signed-off-by: gauron99 <[email protected]>

* fix TestDeploy_ConfigApplied and change pipelines image being used

Signed-off-by: gauron99 <[email protected]>

* fix some tests

Signed-off-by: gauron99 <[email protected]>

* fix actions - return value, configApplied and registry on subsequent deploy different

Signed-off-by: gauron99 <[email protected]>

* update empty image in tests issue

Signed-off-by: gauron99 <[email protected]>

* fix client.Apply tests with passing image value to .Deploy after push

Signed-off-by: gauron99 <[email protected]>

* openshift override on namespace change forced, remove useless print

Signed-off-by: gauron99 <[email protected]>

* printing fixes, reviewdog, buildConfig return

* fix pipelines test by feeding image name to .Deploy, comments

Signed-off-by: gauron99 <[email protected]>

* update more tests

Signed-off-by: gauron99 <[email protected]>

* fix

Signed-off-by: gauron99 <[email protected]>

* new test, comment

Signed-off-by: gauron99 <[email protected]>

* misspell

Signed-off-by: gauron99 <[email protected]>

* remove unnecessary comments

* fix from review

* namespace updated with 2 fields; new error definitions; deploy functionality cleanup

* remove k8s service host var in test

* error definition; fix client tests; cli delete fixup

Signed-off-by: gauron99 <[email protected]>

* new schema

Signed-off-by: gauron99 <[email protected]>

* namespace fixes; remover arguments fix

Signed-off-by: gauron99 <[email protected]>

* delete_test cmd

Signed-off-by: gauron99 <[email protected]>

* schema, new local remote flag instead of deploy

Signed-off-by: gauron99 <[email protected]>

* fix test to have now required namespace

Signed-off-by: gauron99 <[email protected]>

* add namespace check, test action

Signed-off-by: gauron99 <[email protected]>

* fix integration deploy test, comments

Signed-off-by: gauron99 <[email protected]>

* fix wrongly removed namespace

Signed-off-by: gauron99 <[email protected]>

* small changes to remover and ns added to its tests

Signed-off-by: gauron99 <[email protected]>

* test moving logic to client

* fix deploy bug, remove verbose for better logs

* pipelines, clean remover

Signed-off-by: gauron99 <[email protected]>

* newline

Signed-off-by: gauron99 <[email protected]>

* namespace required in remover, and fixed remote deployer - returns ns

Signed-off-by: gauron99 <[email protected]>

* fix integ test for pipelines.Run

Signed-off-by: gauron99 <[email protected]>

* cleanup

Signed-off-by: gauron99 <[email protected]>

* registry update change on deploy, some prints

Signed-off-by: gauron99 <[email protected]>

* new deploy tests and mock update

Signed-off-by: gauron99 <[email protected]>

* new tests, ns determination in mocks

Signed-off-by: gauron99 <[email protected]>

* deploy digested img doesnt populate build

Signed-off-by: gauron99 <[email protected]>

* comments

Signed-off-by: gauron99 <[email protected]>

* remove todo

Signed-off-by: gauron99 <[email protected]>

---------

Signed-off-by: gauron99 <[email protected]>
  • Loading branch information
gauron99 authored Feb 27, 2024
1 parent fcdafd7 commit 7e95ca2
Show file tree
Hide file tree
Showing 44 changed files with 1,475 additions and 509 deletions.
24 changes: 1 addition & 23 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,6 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
}
f = cfg.Configure(f) // Updates f at path to include build request values

// TODO: this logic is duplicated with runDeploy. Shouild be in buildConfig
// constructor.
// Checks if there is a difference between defined registry and its value
// used as a prefix in the image tag In case of a mismatch a new image tag is
// created and used for build.
// Do not react if image tag has been changed outside configuration
if f.Registry != "" && !cmd.Flags().Changed("image") && strings.Index(f.Image, "/") > 0 && !strings.HasPrefix(f.Image, f.Registry) {
prfx := f.Registry
if prfx[len(prfx)-1:] != "/" {
prfx = prfx + "/"
}
sps := strings.Split(f.Image, "/")
updImg := prfx + sps[len(sps)-1]
fmt.Fprintf(cmd.ErrOrStderr(), "Warning: function has current image '%s' which has a different registry than the currently configured registry '%s'. The new image tag will be '%s'. To use an explicit image, use --image.\n", f.Image, f.Registry, updImg)
f.Image = updImg
}

// Client
clientOptions, err := cfg.clientOptions()
if err != nil {
Expand All @@ -193,7 +176,6 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
return
}
}

if err = f.Write(); err != nil {
return
}
Expand Down Expand Up @@ -300,16 +282,12 @@ func (c buildConfig) Prompt() (buildConfig, error) {
// Image Name Override
// Calculate a better image name message which shows the value of the final
// image name as it will be calculated if an explicit image name is not used.
var imagePromptMessageSuffix string
if name := deriveImage(c.Image, c.Registry, c.Path); name != "" {
imagePromptMessageSuffix = fmt.Sprintf(". if not specified, the default '%v' will be used')", name)
}

qs := []*survey.Question{
{
Name: "image",
Prompt: &survey.Input{
Message: fmt.Sprintf("Image name to use (e.g. quay.io/boson/node-sample)%v:", imagePromptMessageSuffix),
Message: "Optionally specify an exact image name to use (e.g. quay.io/boson/node-sample:latest)",
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewClient(cfg ClientConfig, options ...fn.Option) (*fn.Client, func()) {
fn.WithTransport(t),
fn.WithRepositoriesPath(config.RepositoriesPath()),
fn.WithBuilder(buildpacks.NewBuilder(buildpacks.WithVerbose(cfg.Verbose))),
fn.WithRemover(knative.NewRemover(cfg.Namespace, cfg.Verbose)),
fn.WithRemover(knative.NewRemover(cfg.Verbose)),
fn.WithDescriber(knative.NewDescriber(cfg.Namespace, cfg.Verbose)),
fn.WithLister(knative.NewLister(cfg.Namespace, cfg.Verbose)),
fn.WithDeployer(d),
Expand Down
4 changes: 3 additions & 1 deletion cmd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"knative.dev/func/pkg/mock"
)

const namespace = "func"

// Test_NewTestClient ensures that the convenience method for
// constructing a mocked client for testing properly considers options:
// options provided to the factory constructor are considered exaustive,
Expand All @@ -26,7 +28,7 @@ func Test_NewTestClient(t *testing.T) {
client, _ := clientFn(ClientConfig{}, fn.WithDescriber(describer))

// Trigger an invocation of the mocks
err := client.Remove(context.Background(), fn.Function{Name: "test"}, true)
err := client.Remove(context.Background(), fn.Function{Name: "test", Deploy: fn.DeploySpec{Namespace: namespace}}, true)
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 0 additions & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func runCreate(cmd *cobra.Command, args []string, newClient ClientFactory) (err
if err != nil {
return err
}

// Confirm
fmt.Fprintf(cmd.OutOrStderr(), "Created %v function in %v\n", cfg.Runtime, cfg.Path)
return nil
Expand Down
17 changes: 12 additions & 5 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ func runDelete(cmd *cobra.Command, args []string, newClient ClientFactory) (err
return
}

// check that name is defined when deleting a Function in specific namespace
if cfg.Name == "" && cfg.Namespace != "" {
return fmt.Errorf("function name is required when namespace is specified")
}

var function fn.Function
// initialize namespace from the config
var namespace = cfg.Namespace

// Initialize func with explicit name (when provided)
if len(args) > 0 && args[0] != "" {
Expand All @@ -84,17 +91,17 @@ func runDelete(cmd *cobra.Command, args []string, newClient ClientFactory) (err
return fn.NewErrNotInitialized(function.Root)
}

// If not provided, use the function's extant namespace
if !cmd.Flags().Changed("namespace") {
cfg.Namespace = function.Deploy.Namespace
// use the function's extant namespace -- already deployed function
if !cmd.Flags().Changed("namespace") && function.Deploy.Namespace != "" {
namespace = function.Deploy.Namespace
}

}

// Create a client instance from the now-final config
client, done := newClient(ClientConfig{Namespace: cfg.Namespace, Verbose: cfg.Verbose})
client, done := newClient(ClientConfig{Namespace: namespace, Verbose: cfg.Verbose})
defer done()

function.Deploy.Namespace = namespace
// Invoke remove using the concrete client impl
return client.Remove(cmd.Context(), function, cfg.DeleteAll)
}
Expand Down
Loading

0 comments on commit 7e95ca2

Please sign in to comment.