Skip to content

Commit c2ad8fb

Browse files
committed
feat(expand CRDs): Changed typing of CRD object to simplify data handling
1 parent 72fce7b commit c2ad8fb

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

pkg/apis/vaultwebhook.uswitch.com/v1alpha1/types.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha1
22

33
import (
4+
corev1 "k8s.io/api/core/v1"
45
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
56
)
67

@@ -34,17 +35,5 @@ type DatabaseCredentialBindingList struct {
3435
}
3536

3637
type Container struct {
37-
Lifecycle Lifecycle `json:"lifecycle,omitempty"`
38-
}
39-
40-
type Lifecycle struct {
41-
PreStop LifecycleHandler `json:"preStop,omitempty"`
42-
}
43-
44-
type LifecycleHandler struct {
45-
Exec ExecAction `json:"exec,omitempty"`
46-
}
47-
48-
type ExecAction struct {
49-
Command []string `json:"command,omitempty"`
38+
Lifecycle corev1.Lifecycle `json:"lifecycle,omitempty"`
5039
}

vault.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,17 @@ func appendVolumeMountIfMissing(slice []corev1.VolumeMount, v corev1.VolumeMount
207207
return append(slice, v)
208208
}
209209

210+
// Conditionally set Lifecycle if it exists in containerSpec
210211
func addLifecycleHook(container corev1.Container, containerSpec v1alpha1.Container) corev1.Container {
211-
// Conditionally set Lifecycle if it exists in containerSpec
212-
if len(containerSpec.Lifecycle.PreStop.Exec.Command) > 0 {
213-
container.Lifecycle = &corev1.Lifecycle{
214-
PreStop: &corev1.LifecycleHandler{
215-
Exec: &corev1.ExecAction{
216-
Command: containerSpec.Lifecycle.PreStop.Exec.Command,
217-
},
218-
},
219-
}
220-
// TODO: Fix support for initcontainer's Lifecycle hooks ( Go dep to be updated )
221-
// Init containers must have RestartPolicy=Always to be able to support Lifecycle hooks
222-
// if isInit {
223-
// restartPolicy := corev1.ContainerRestartPolicyAlways
224-
// container.RestartPolicy = &restartPolicy
225-
// }
212+
if container.Lifecycle != nil {
213+
container.Lifecycle = &containerSpec.Lifecycle
226214
}
215+
// TODO: Fix support for initcontainer's Lifecycle hooks ( Go dep to be updated )
216+
// Init containers must have RestartPolicy=Always to be able to support Lifecycle hooks
217+
// if isInit {
218+
// restartPolicy := corev1.ContainerRestartPolicyAlways
219+
// container.RestartPolicy = &restartPolicy
220+
// }
221+
//}
227222
return container
228223
}

webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func matchBindings(bindings []v1alpha1.DatabaseCredentialBinding, serviceAccount
198198
if output == "" {
199199
output = "/etc/database"
200200
}
201-
//log.Infof("[matchBindings] Printing content of Container: %+v", binding.Spec.Container)
201+
log.Infof("[matchBindings] Printing content of Container: %+v", binding.Spec.Container)
202202
//log.Infof("[matchBindings] Printing content of InitContainer: %+v", binding.Spec.InitContainer)
203203

204204
matchedBindings = appendIfMissing(matchedBindings, database{

0 commit comments

Comments
 (0)