Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup orphaned func, new image-name calculation #1962

Merged
merged 53 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0807950
forced namespace change, deletes old func, kind works
gauron99 Sep 4, 2023
0f6c92f
new .deploy.image field
gauron99 Sep 4, 2023
e3fe80d
building
gauron99 Oct 10, 2023
3a6fdb3
building
gauron99 Oct 10, 2023
c87167e
add first iteration of complete functionality with f.Build.Image and …
gauron99 Nov 1, 2023
fdf34f9
base tests fixes for compile
gauron99 Nov 1, 2023
35d1916
fix base tests2 for now, integration test has a possible TODO
gauron99 Nov 1, 2023
2b1ba95
new generated schema
gauron99 Nov 1, 2023
318b376
fix some tests using .Image and create new test
gauron99 Nov 6, 2023
4f061ce
remove nested .func
gauron99 Nov 6, 2023
00cd46f
get rid of test
gauron99 Nov 7, 2023
2d3dfa3
remove my debug test
gauron99 Nov 13, 2023
c81a191
fix namespace change test
gauron99 Nov 13, 2023
6cacae4
fix pipeline run to use .Deploy.Image
gauron99 Nov 13, 2023
3e4a773
fix TestDeploy_ConfigApplied and change pipelines image being used
gauron99 Nov 14, 2023
ec6dd06
fix some tests
gauron99 Nov 27, 2023
29008ab
fix actions - return value, configApplied and registry on subsequent …
gauron99 Dec 4, 2023
809adf7
update empty image in tests issue
gauron99 Dec 8, 2023
a2abf0c
fix client.Apply tests with passing image value to .Deploy after push
gauron99 Dec 9, 2023
4b4305b
openshift override on namespace change forced, remove useless print
gauron99 Dec 10, 2023
37e810a
printing fixes, reviewdog, buildConfig return
gauron99 Dec 10, 2023
4e1f4f5
fix pipelines test by feeding image name to .Deploy, comments
gauron99 Dec 11, 2023
434cc0e
update more tests
gauron99 Dec 12, 2023
b7478b0
fix
gauron99 Dec 12, 2023
971e735
new test, comment
gauron99 Dec 12, 2023
070dcde
misspell
gauron99 Dec 12, 2023
b5a7bde
remove unnecessary comments
gauron99 Dec 13, 2023
2c48fee
fix from review
gauron99 Jan 2, 2024
2225fff
namespace updated with 2 fields; new error definitions; deploy functi…
gauron99 Jan 10, 2024
c18bc76
remove k8s service host var in test
gauron99 Jan 10, 2024
c809be5
error definition; fix client tests; cli delete fixup
gauron99 Jan 10, 2024
a1e193c
new schema
gauron99 Jan 10, 2024
75fbd28
namespace fixes; remover arguments fix
gauron99 Jan 22, 2024
5054422
delete_test cmd
gauron99 Jan 22, 2024
ce899c0
schema, new local remote flag instead of deploy
gauron99 Jan 22, 2024
3fe827a
fix test to have now required namespace
gauron99 Jan 25, 2024
8465c80
add namespace check, test action
gauron99 Jan 29, 2024
e5e5f2f
fix integration deploy test, comments
gauron99 Jan 30, 2024
6d9c667
fix wrongly removed namespace
gauron99 Jan 30, 2024
b19613b
small changes to remover and ns added to its tests
gauron99 Jan 31, 2024
4691a76
test moving logic to client
gauron99 Feb 1, 2024
5dc0ecc
fix deploy bug, remove verbose for better logs
gauron99 Feb 1, 2024
3f32aae
pipelines, clean remover
gauron99 Feb 2, 2024
76e606e
newline
gauron99 Feb 4, 2024
e3b8599
namespace required in remover, and fixed remote deployer - returns ns
gauron99 Feb 4, 2024
686fcee
fix integ test for pipelines.Run
gauron99 Feb 4, 2024
8a9de10
cleanup
gauron99 Feb 6, 2024
9d1d9f0
registry update change on deploy, some prints
gauron99 Feb 8, 2024
9b506cd
new deploy tests and mock update
gauron99 Feb 9, 2024
507fb0c
new tests, ns determination in mocks
gauron99 Feb 12, 2024
db2176f
deploy digested img doesnt populate build
gauron99 Feb 12, 2024
716401b
comments
gauron99 Feb 19, 2024
5cb7e1a
remove todo
gauron99 Feb 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: usually in test files one uses a name like TestNamespace with an associated doc string, this helps 1) readers of the code immediately know it is a globally-scoped and test-specific variable, and 2) readers of the docs can see (without looking at the code) that the default namespace for this package is 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
Loading