feat: deploy success message also displays the namespace (#1090)

* func deploy should display namespace

* Modified e2e to consider namespace

* Added Namespace field in DeploymentResult struct

* Modified unit test for client deploy

* e2e fix
This commit is contained in:
Gunjan Vyas 2022-07-06 22:04:08 +05:30 committed by GitHub
parent 416ada6715
commit afd224fe5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 16 deletions

View File

@ -90,8 +90,9 @@ type Deployer interface {
}
type DeploymentResult struct {
Status Status
URL string
Status Status
URL string
Namespace string
}
// Status of the Function from the DeploymentResult
@ -699,10 +700,11 @@ func (c *Client) Deploy(ctx context.Context, path string) (err error) {
// Deploy a new or Update the previously-deployed Function
c.progressListener.Increment("Deploying function to the cluster")
result, err := c.deployer.Deploy(ctx, f)
if result.Status == Deployed {
c.progressListener.Increment(fmt.Sprintf("Function deployed at URL: %v", result.URL))
c.progressListener.Increment(fmt.Sprintf("Function deployed in namespace %q and exposed at URL: \n%v", result.Namespace, result.URL))
} else if result.Status == Updated {
c.progressListener.Increment(fmt.Sprintf("Function updated at URL: %v", result.URL))
c.progressListener.Increment(fmt.Sprintf("Function updated in namespace %q and exposed at URL: \n%v", result.Namespace, result.URL))
}
return err

View File

@ -581,7 +581,16 @@ func TestClient_Update(t *testing.T) {
expectedImage = "example.com/alice/testUpdate:latest"
builder = mock.NewBuilder()
pusher = mock.NewPusher()
deployer = mock.NewDeployer()
deployer = mock.NewDeployerWithResult(&fn.DeploymentResult{
Status: fn.Deployed,
URL: "example.com",
Namespace: "test-ns",
})
deployerUpdated = mock.NewDeployerWithResult(&fn.DeploymentResult{
Status: fn.Updated,
URL: "example.com",
Namespace: "test-ns",
})
)
// Create the root Function directory
@ -646,6 +655,28 @@ func TestClient_Update(t *testing.T) {
if !deployer.DeployInvoked {
t.Fatal("deployer was not invoked")
}
client = fn.New(
fn.WithRegistry(TestRegistry),
fn.WithBuilder(builder),
fn.WithPusher(pusher),
fn.WithDeployer(deployerUpdated))
// Invoke the update, triggering the Function delegates, and
// perform follow-up assertions that the Functions were indeed invoked during the update.
if err := client.Deploy(context.Background(), root); err != nil {
t.Fatal(err)
}
if !builder.BuildInvoked {
t.Fatal("builder was not invoked")
}
if !pusher.PushInvoked {
t.Fatal("pusher was not invoked")
}
if !deployerUpdated.DeployInvoked {
t.Fatal("deployer was not invoked")
}
}
// TestClient_Remove_ByPath ensures that the remover is invoked to remove

View File

@ -73,7 +73,8 @@ func (d *Deployer) isImageInPrivateRegistry(ctx context.Context, client clientse
return false
}
func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (result fn.DeploymentResult, err error) {
func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (fn.DeploymentResult, error) {
var err error
if d.Namespace == "" {
d.Namespace, err = k8s.GetNamespace(d.Namespace)
if err != nil {
@ -161,11 +162,12 @@ func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (result fn.Deploym
}
if d.verbose {
fmt.Println("Function deployed at URL: " + route.Status.URL.String())
fmt.Printf("Function deployed in namespace %q and exposed at URL:\n%s\n", d.Namespace, route.Status.URL.String())
}
return fn.DeploymentResult{
Status: fn.Deployed,
URL: route.Status.URL.String(),
Status: fn.Deployed,
URL: route.Status.URL.String(),
Namespace: d.Namespace,
}, nil
} else {
@ -206,8 +208,9 @@ func (d *Deployer) Deploy(ctx context.Context, f fn.Function) (result fn.Deploym
}
return fn.DeploymentResult{
Status: fn.Updated,
URL: route.Status.URL.String(),
Status: fn.Updated,
URL: route.Status.URL.String(),
Namespace: d.Namespace,
}, nil
}
}

View File

@ -9,6 +9,7 @@ import (
type Deployer struct {
DeployInvoked bool
DeployFn func(fn.Function) error
DeployResult *fn.DeploymentResult
}
func NewDeployer() *Deployer {
@ -17,7 +18,17 @@ func NewDeployer() *Deployer {
}
}
func NewDeployerWithResult(result *fn.DeploymentResult) *Deployer {
return &Deployer{
DeployFn: func(fn.Function) error { return nil },
DeployResult: result,
}
}
func (i *Deployer) Deploy(ctx context.Context, f fn.Function) (fn.DeploymentResult, error) {
i.DeployInvoked = true
if i.DeployResult != nil {
return *i.DeployResult, i.DeployFn(f)
}
return fn.DeploymentResult{}, i.DeployFn(f)
}

View File

@ -158,9 +158,9 @@ func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) error {
}
if ksvc.Generation == 1 {
pp.progressListener.Increment(fmt.Sprintf("Function deployed at URL: %s", ksvc.Status.URL.String()))
pp.progressListener.Increment(fmt.Sprintf("Function deployed in namespace %q and exposed at URL: \n%s", ksvc.Namespace, ksvc.Status.URL.String()))
} else {
pp.progressListener.Increment(fmt.Sprintf("Function updated at URL: %s", ksvc.Status.URL.String()))
pp.progressListener.Increment(fmt.Sprintf("Function updated in namespace %q and exposed at URL: \n%s", ksvc.Namespace, ksvc.Status.URL.String()))
}
return nil

View File

@ -27,17 +27,17 @@ func Deploy(t *testing.T, knFunc *TestShellCmdRunner, project *FunctionTestProje
// "Function [deployed|updated] at URL: http://nodefunc.default.192.168.39.188.nip.io"
// Here we extract the URL and store on project setting so that can be used later
// to validate actual function responsiveness.
wasDeployed := regexp.MustCompile("Function [a-z]* at URL: http.*").MatchString(cleanStdout)
wasDeployed := regexp.MustCompile("Function [a-z]* in namespace .* at URL: \nhttp.*").MatchString(cleanStdout)
if !wasDeployed {
t.Fatal("Function was not deployed")
}
urlMatch := regexp.MustCompile("(URL: http.*)").FindString(cleanStdout)
urlMatch := regexp.MustCompile("(URL: \nhttp.*)").FindString(cleanStdout)
if urlMatch == "" {
t.Fatal("URL not returned on output")
}
project.FunctionURL = strings.Split(urlMatch, " ")[1]
project.FunctionURL = strings.Split(urlMatch, "\n")[1]
project.IsDeployed = true
}