@@ -23,11 +23,11 @@ import (
23
23
"encoding/pem"
24
24
"fmt"
25
25
26
+ "github.com/heptio/sonobuoy/pkg/plugin"
26
27
"github.com/heptio/sonobuoy/pkg/plugin/manifest"
27
28
"github.com/pkg/errors"
28
29
v1 "k8s.io/api/core/v1"
29
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
- kuberuntime "k8s.io/apimachinery/pkg/runtime"
31
31
)
32
32
33
33
// Base is the struct that stores state for plugin drivers and contains helper methods.
@@ -42,23 +42,6 @@ type Base struct {
42
42
CustomAnnotations map [string ]string
43
43
}
44
44
45
- // TemplateData is all the fields available to plugin driver templates.
46
- type TemplateData struct {
47
- PluginName string
48
- ResultType string
49
- SessionID string
50
- Namespace string
51
- SonobuoyImage string
52
- ImagePullPolicy string
53
- ImagePullSecrets string
54
- CustomAnnotations map [string ]string
55
- ProducerContainer string
56
- MasterAddress string
57
- CACert string
58
- SecretName string
59
- ExtraVolumes []string
60
- }
61
-
62
45
// GetSessionID returns the session id associated with the plugin.
63
46
func (b * Base ) GetSessionID () string {
64
47
return b .SessionID
@@ -94,42 +77,6 @@ func (b *Base) GetResultFiles() []string {
94
77
return b .Definition .SonobuoyConfig .ResultFiles
95
78
}
96
79
97
- //GetTemplateData fills a TemplateData struct with the passed in and state variables.
98
- func (b * Base ) GetTemplateData (masterAddress string , cert * tls.Certificate ) (* TemplateData , error ) {
99
-
100
- container , err := kuberuntime .Encode (manifest .Encoder , & b .Definition .Spec )
101
- if err != nil {
102
- return nil , errors .Wrapf (err , "couldn't reserialize container for job %q" , b .Definition .SonobuoyConfig .PluginName )
103
- }
104
-
105
- volumes := make ([]string , len (b .Definition .ExtraVolumes ))
106
- for i , volume := range b .Definition .ExtraVolumes {
107
- enc , err := kuberuntime .Encode (manifest .Encoder , & volume )
108
- if err != nil {
109
- return nil , errors .Wrap (err , "couldn't serialize extra volume" )
110
- }
111
- volumes [i ] = string (enc )
112
- }
113
-
114
- cacert := getCACertPEM (cert )
115
-
116
- return & TemplateData {
117
- PluginName : b .Definition .SonobuoyConfig .PluginName ,
118
- ResultType : b .Definition .SonobuoyConfig .ResultType ,
119
- SessionID : b .SessionID ,
120
- Namespace : b .Namespace ,
121
- SonobuoyImage : b .SonobuoyImage ,
122
- ImagePullPolicy : b .ImagePullPolicy ,
123
- ImagePullSecrets : b .ImagePullSecrets ,
124
- CustomAnnotations : b .CustomAnnotations ,
125
- ProducerContainer : string (container ),
126
- MasterAddress : masterAddress ,
127
- CACert : cacert ,
128
- SecretName : b .GetSecretName (),
129
- ExtraVolumes : volumes ,
130
- }, nil
131
- }
132
-
133
80
// MakeTLSSecret makes a Kubernetes secret object for the given TLS certificate.
134
81
func (b * Base ) MakeTLSSecret (cert * tls.Certificate ) (* v1.Secret , error ) {
135
82
rsaKey , ok := cert .PrivateKey .(* ecdsa.PrivateKey )
@@ -192,3 +139,75 @@ func getKeyPEM(key *ecdsa.PrivateKey) ([]byte, error) {
192
139
Bytes : derKEY ,
193
140
}), nil
194
141
}
142
+
143
+ func (b * Base ) workerEnvironment (hostname string , cert * tls.Certificate ) []v1.EnvVar {
144
+ envVars := []v1.EnvVar {
145
+ {
146
+ Name : "NODE_NAME" ,
147
+ ValueFrom : & v1.EnvVarSource {
148
+ FieldRef : & v1.ObjectFieldSelector {
149
+ FieldPath : "spec.nodeName" ,
150
+ },
151
+ },
152
+ },
153
+ {
154
+ Name : "RESULTS_DIR" ,
155
+ Value : plugin .ResultsDir ,
156
+ },
157
+ {
158
+ Name : "RESULT_TYPE" ,
159
+ Value : b .GetResultType (),
160
+ },
161
+ {
162
+ Name : "MASTER_URL" ,
163
+ Value : hostname ,
164
+ },
165
+ {
166
+ Name : "CA_CERT" ,
167
+ Value : getCACertPEM (cert ),
168
+ },
169
+ {
170
+ Name : "CLIENT_CERT" ,
171
+ ValueFrom : & v1.EnvVarSource {
172
+ SecretKeyRef : & v1.SecretKeySelector {
173
+ LocalObjectReference : v1.LocalObjectReference {
174
+ Name : b .GetSecretName (),
175
+ },
176
+ Key : "tls.crt" ,
177
+ },
178
+ },
179
+ },
180
+ {
181
+ Name : "CLIENT_KEY" ,
182
+ ValueFrom : & v1.EnvVarSource {
183
+ SecretKeyRef : & v1.SecretKeySelector {
184
+ LocalObjectReference : v1.LocalObjectReference {
185
+ Name : b .GetSecretName (),
186
+ },
187
+ Key : "tls.key" ,
188
+ },
189
+ },
190
+ },
191
+ }
192
+ return envVars
193
+ }
194
+
195
+ // CreateWorkerContainerDefintion creates the container definition to run the Sonobuoy worker for a plugin.
196
+ func (b * Base ) CreateWorkerContainerDefintion (hostname string , cert * tls.Certificate , command , args []string ) v1.Container {
197
+ container := v1.Container {
198
+ Name : "sonobuoy-worker" ,
199
+ Image : b .SonobuoyImage ,
200
+ Command : command ,
201
+ Args : args ,
202
+ Env : b .workerEnvironment (hostname , cert ),
203
+ ImagePullPolicy : v1 .PullPolicy (b .ImagePullPolicy ),
204
+ VolumeMounts : []v1.VolumeMount {
205
+ {
206
+ Name : "results" ,
207
+ ReadOnly : false ,
208
+ MountPath : plugin .ResultsDir ,
209
+ },
210
+ },
211
+ }
212
+ return container
213
+ }
0 commit comments