Skip to content

Commit 9ba53ff

Browse files
committed
create a clusterpodconvention with a ytt template
1 parent f24da47 commit 9ba53ff

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

pkg/apis/conventions/v1alpha1/clusterpodconvention_validation.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ func (s *ClusterPodConventionSpec) Validate() validation.FieldErrors {
7979
} else {
8080
// validate via the ytt field as well
8181
// return multiple errors for this to request a desired configuration
82-
errs = errs.Also(s.Webhook.Validate().ViaField("webhook"))
82+
83+
// only invoke webhook validations if the ytt configuration is not being used
84+
if s.Ytt == nil && s.Webhook != nil {
85+
errs = errs.Also(s.Webhook.Validate().ViaField("webhook"))
86+
}
87+
// errs = errs.Also(s.Ytt.Validate().ViaField("ytt"))
8388
}
8489

8590
if s.SelectorTarget != PodTemplateSpecLabels && s.SelectorTarget != PodIntentLabels {
@@ -88,10 +93,17 @@ func (s *ClusterPodConventionSpec) Validate() validation.FieldErrors {
8893
`Accepted selector target values are "PodIntent" and "PodTemplateSpec". The default value is set to "PodTemplateSpec"`),
8994
})
9095
}
91-
9296
return errs
9397
}
9498

99+
// func (s *ClusterPodConventionYttTemplate) Validate() validation.FieldErrors {
100+
// errs := validation.FieldErrors{}
101+
// if s.Template == "" {
102+
// errs = errs.Also(validation.ErrMissingField("template"))
103+
// }
104+
// return errs
105+
// }
106+
95107
func (s *ClusterPodConventionWebhook) Validate() validation.FieldErrors {
96108
errs := validation.FieldErrors{}
97109

pkg/binding/convention.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Convention struct {
3434
Selectors []metav1.LabelSelector
3535
Priority conventionsv1alpha1.PriorityLevel
3636
ClientConfig admissionregistrationv1.WebhookClientConfig
37+
YTTTemplate conventionsv1alpha1.ClusterPodConventionYttTemplate
3738
}
3839

3940
func (o *Convention) Apply(ctx context.Context, conventionRequest *webhookv1alpha1.PodConventionContext, wc WebhookConfig) (*webhookv1alpha1.PodConventionContext, error) {

pkg/binding/conventions.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,12 @@ func (c *Conventions) Sort() Conventions {
8484
return originalConventions
8585
}
8686

87-
func (c *Conventions) Apply(ctx context.Context,
88-
parent *conventionsv1alpha1.PodIntent,
89-
wc WebhookConfig,
90-
rc RegistryConfig,
91-
) (*corev1.PodTemplateSpec, error) {
87+
func (c *Conventions) Apply(ctx context.Context, parent *conventionsv1alpha1.PodIntent, wc WebhookConfig, rc RegistryConfig) (*corev1.PodTemplateSpec, error) {
9288
log := logr.FromContextOrDiscard(ctx)
9389
if parent == nil {
9490
return nil, fmt.Errorf("pod intent is not set")
9591
}
92+
// extract the pod template spec
9693
workload := parent.Spec.Template.AsPodTemplateSpec()
9794
appliedConventions := []string{}
9895
if str := workload.Annotations[conventionsv1alpha1.AppliedConventionsAnnotationKey]; str != "" {
@@ -105,6 +102,7 @@ func (c *Conventions) Apply(ctx context.Context,
105102
log.Error(err, "fetching metadata for Images failed")
106103
return nil, fmt.Errorf("fetching metadata for Images failed: %v", err)
107104
}
105+
108106
conventionRequestObj := &webhookv1alpha1.PodConventionContext{
109107
ObjectMeta: metav1.ObjectMeta{
110108
Name: fmt.Sprintf("%s-%s", parent.GetName(), convention.Name),

pkg/controllers/podintent_reconciler.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ func ResolveConventions() reconcilers.SubReconciler {
9898
Name: "ResolveConventions",
9999
Sync: func(ctx context.Context, parent *conventionsv1alpha1.PodIntent) error {
100100
log := logr.FromContextOrDiscard(ctx)
101-
log.Info("HERE FIRST =========")
102101
c := reconcilers.RetrieveConfigOrDie(ctx)
103102
sources := &conventionsv1alpha1.ClusterPodConventionList{}
104103
if err := c.List(ctx, sources); err != nil {
@@ -109,11 +108,15 @@ func ResolveConventions() reconcilers.SubReconciler {
109108
for i := range sources.Items {
110109
source := sources.Items[i].DeepCopy()
111110
source.Default()
111+
112112
convention := binding.Convention{
113113
Name: source.Name,
114114
Selectors: source.Spec.Selectors,
115115
Priority: source.Spec.Priority,
116116
}
117+
118+
log.Info("created convention ... ", convention)
119+
117120
if source.Spec.Webhook != nil {
118121
clientConfig := source.Spec.Webhook.ClientConfig.DeepCopy()
119122
if source.Spec.Webhook.Certificate != nil {
@@ -128,6 +131,7 @@ func ResolveConventions() reconcilers.SubReconciler {
128131
}
129132
convention.ClientConfig = *clientConfig
130133
} else if source.Spec.Ytt != nil {
134+
log.Info("handling a ytt based convention")
131135
// read template spec and convenert to a sptream of bytes
132136
// template
133137
template := &parent.Spec.Template

0 commit comments

Comments
 (0)