/
addon.go
126 lines (108 loc) · 3.82 KB
/
addon.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright 2019 The Jetstack cert-manager contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package certmanager
import (
"fmt"
"os/exec"
"github.com/jetstack/cert-manager/test/e2e/framework/addon/chart"
"github.com/jetstack/cert-manager/test/e2e/framework/addon/tiller"
"github.com/jetstack/cert-manager/test/e2e/framework/config"
)
// Certmanager defines an addon that installs an instance of certmanager in the
// target cluster.
// Currently, only one instance of Certmanager can be deployed in a single
// invocation of the test suite (i.e. it *must* be instantiated globally).
// In future we can restrict Certmanager to a single namespace in order to enforce
// isolation between tests.
type Certmanager struct {
config *config.Config
chart *chart.Chart
tillerDetails *tiller.Details
// Tiller is the tiller instance used to deploy the chart
Tiller *tiller.Tiller
Name string
// Required namespace to deploy Certmanager into.
Namespace string
}
// Details return the details about the certmanager instance deployed
type Details struct {
ClusterResourceNamespace string
ServiceAccountName string
}
func (p *Certmanager) Setup(cfg *config.Config) error {
p.config = cfg
if p.Name == "" {
return fmt.Errorf("Name field must be set on Certmanager addon")
}
if p.Namespace == "" {
// TODO: in non-global instances, we could generate a new namespace just
// for this addon to be used from.
return fmt.Errorf("Namespace name must be specified")
}
if p.Tiller == nil {
return fmt.Errorf("Tiller field must be set on Certmanager addon")
}
if p.config.Kubectl == "" {
return fmt.Errorf("path to kubectl must be provided")
}
var err error
p.tillerDetails, err = p.Tiller.Details()
if err != nil {
return err
}
p.chart = &chart.Chart{
Tiller: p.Tiller,
ReleaseName: "chart-certmanager-" + p.Name,
Namespace: p.Namespace,
ChartName: cfg.RepoRoot + "/deploy/charts/cert-manager",
// TODO: move resource requests/limits into Vars so they are always set
Values: []string{cfg.RepoRoot + "/test/fixtures/cert-manager-values.yaml"},
Vars: []chart.StringTuple{
{Key: "serviceAccount.name", Value: "chart-certmanager-cert-manager"},
},
// doesn't matter when installing from disk
ChartVersion: "0",
UpdateDeps: true,
}
err = p.chart.Setup(cfg)
if err != nil {
return err
}
return nil
}
// Provision will actually deploy this instance of Pebble-ingress to the cluster.
func (p *Certmanager) Provision() error {
if err := exec.Command(p.config.Kubectl, "apply", "-f", p.config.RepoRoot+"/deploy/manifests/00-crds.yaml").Run(); err != nil {
return fmt.Errorf("error install cert-manager CRD manifests: %v", err)
}
return p.chart.Provision()
}
// Details returns details that can be used to utilise the instance of Pebble.
func (p *Certmanager) Details() *Details {
return &Details{
ClusterResourceNamespace: p.Namespace,
ServiceAccountName: "chart-certmanager-cert-manager",
}
}
// Deprovision will destroy this instance of Pebble
func (p *Certmanager) Deprovision() error {
return p.chart.Deprovision()
}
func (p *Certmanager) SupportsGlobal() bool {
// Pebble does support a global configuration, as the 'usage details' for
// it are deterministic (i.e. not a result of the call to helm install).
return true
}
func (p *Certmanager) Logs() (map[string]string, error) {
return p.chart.Logs()
}