/
app.go
80 lines (70 loc) · 2.05 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package app
import (
"context"
"github.com/hashicorp/go-multierror"
"github.com/kyma-project/kyma/tests/function-controller/internal/executor"
"github.com/kyma-project/kyma/tests/function-controller/internal/utils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
appsCli "k8s.io/client-go/kubernetes/typed/apps/v1"
coreclient "k8s.io/client-go/kubernetes/typed/core/v1"
)
var _ executor.Step = &Application{}
/*
Application consist of deployment and service
*/
type Application struct {
deployment Deployment
svc Service
name string
stepName string
namespace string
log *logrus.Entry
port int32
image string
}
func NewApplication(stepName, name string, image string, port int32, appCli appsCli.DeploymentInterface, coreCli coreclient.ServiceInterface, c utils.Container) executor.Step {
return &Application{
deployment: NewDeployment(name, c.Namespace, image, port, appCli, c.Log),
svc: NewService(name, c.Namespace, port, coreCli, c.Log),
name: name,
stepName: stepName,
namespace: c.Namespace,
log: c.Log,
port: port,
image: image,
}
}
func (a Application) Name() string {
return a.name
}
func (a Application) Run() error {
err := a.deployment.Create()
if err != nil {
return errors.Wrap(err, "while creating deployment for application")
}
err = a.svc.Create()
if err != nil {
return errors.Wrap(err, "while creating service for application ")
}
return nil
}
func (a Application) Cleanup() error {
ctx := context.Background()
deploymentErr := a.deployment.Delete(ctx, metav1.DeleteOptions{})
svcErr := a.svc.Delete(ctx, metav1.DeleteOptions{})
err := multierror.Append(deploymentErr, svcErr)
return err.ErrorOrNil()
}
func (a Application) OnError() error {
err := a.svc.LogResource()
if err != nil {
return errors.Wrap(err, "while logging application service status")
}
err = a.deployment.LogResource()
if err != nil {
return errors.Wrap(err, "while logging application deployment status")
}
return nil
}