Skip to content

Commit

Permalink
Remove old deprecated fields from v1beta1 types
Browse files Browse the repository at this point in the history
These fields will still be supported in the v1alpha1 types.
  • Loading branch information
dibyom authored and tekton-robot committed Jun 4, 2021
1 parent b0339de commit d7cb6f7
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 559 deletions.
50 changes: 0 additions & 50 deletions pkg/apis/triggers/v1beta1/event_listener_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"context"

"github.com/tektoncd/triggers/pkg/apis/triggers/contexts"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"
)

// SetDefaults sets the defaults on the object.
Expand All @@ -38,55 +36,7 @@ func (el *EventListener) SetDefaults(ctx context.Context) {
triggerSpecBindingArray(el.Spec.Triggers[i].Bindings).defaultBindings()
for _, ti := range t.Interceptors {
ti.defaultInterceptorKind()
if err := ti.updateCoreInterceptors(); err != nil {
// The err only happens due to malformed JSON and should never really happen
// We can't return an error here, so print out the error
logger := logging.FromContext(ctx)
logger.Errorf("failed to setDefaults for trigger: %s; err: %s", t.Name, err)
}
}
}
el.Spec.updatePodTemplate()
// To be removed in a later release #1020
el.Spec.updateReplicas()
}
}

func (spec *EventListenerSpec) updatePodTemplate() {
if spec.DeprecatedPodTemplate != nil {
if spec.DeprecatedPodTemplate.NodeSelector != nil {
if spec.Resources.KubernetesResource == nil {
spec.Resources.KubernetesResource = &KubernetesResource{}
}
spec.Resources.KubernetesResource.Template.Spec.NodeSelector = spec.DeprecatedPodTemplate.NodeSelector
spec.DeprecatedPodTemplate.NodeSelector = nil
}
if spec.DeprecatedPodTemplate.Tolerations != nil {
if spec.Resources.KubernetesResource == nil {
spec.Resources.KubernetesResource = &KubernetesResource{}
}
spec.Resources.KubernetesResource.Template.Spec.Tolerations = spec.DeprecatedPodTemplate.Tolerations
spec.DeprecatedPodTemplate.Tolerations = nil
}
spec.DeprecatedPodTemplate = nil
}
}

// To be Removed in a later release #1020
func (spec *EventListenerSpec) updateReplicas() {
if spec.DeprecatedReplicas != nil {
if *spec.DeprecatedReplicas == 0 {
if spec.Resources.KubernetesResource == nil {
spec.Resources.KubernetesResource = &KubernetesResource{}
}
spec.Resources.KubernetesResource.Replicas = ptr.Int32(1)
spec.DeprecatedReplicas = nil
} else if *spec.DeprecatedReplicas > 0 {
if spec.Resources.KubernetesResource == nil {
spec.Resources.KubernetesResource = &KubernetesResource{}
}
spec.Resources.KubernetesResource.Replicas = spec.DeprecatedReplicas
spec.DeprecatedReplicas = nil
}
}
}
80 changes: 0 additions & 80 deletions pkg/apis/triggers/v1beta1/event_listener_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/triggers/pkg/apis/triggers/contexts"
"github.com/tektoncd/triggers/pkg/apis/triggers/v1beta1"
corev1 "k8s.io/api/core/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/ptr"
)

Expand Down Expand Up @@ -76,23 +74,6 @@ func TestEventListenerSetDefaults(t *testing.T) {
}},
},
},
}, {
name: "set replicas to 1 if provided deprecated replicas is 0 as part of eventlistener spec",
in: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
DeprecatedReplicas: ptr.Int32(0),
},
},
wc: contexts.WithUpgradeViaDefaulting,
want: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
Resources: v1beta1.Resources{
KubernetesResource: &v1beta1.KubernetesResource{
Replicas: ptr.Int32(1),
},
},
},
},
}, {
name: "set replicas to 1 if provided replicas is 0 as part of eventlistener kubernetesResources",
in: &v1beta1.EventListener{
Expand All @@ -114,50 +95,6 @@ func TestEventListenerSetDefaults(t *testing.T) {
},
},
},
}, {
name: "deprecate podTemplate nodeselector to resource",
in: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
DeprecatedPodTemplate: &v1beta1.PodTemplate{
NodeSelector: map[string]string{"beta.kubernetes.io/os": "linux"},
},
},
},
wc: contexts.WithUpgradeViaDefaulting,
want: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
Resources: v1beta1.Resources{
KubernetesResource: &v1beta1.KubernetesResource{
WithPodSpec: duckv1.WithPodSpec{
Template: duckv1.PodSpecable{
Spec: corev1.PodSpec{
NodeSelector: map[string]string{"beta.kubernetes.io/os": "linux"},
},
},
}},
},
},
},
}, {
name: "deprecate podTemplate toleration to resource",
in: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
DeprecatedPodTemplate: &v1beta1.PodTemplate{Tolerations: []corev1.Toleration{{Key: "key"}}},
},
},
wc: contexts.WithUpgradeViaDefaulting,
want: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
Resources: v1beta1.Resources{
KubernetesResource: &v1beta1.KubernetesResource{
WithPodSpec: duckv1.WithPodSpec{
Template: duckv1.PodSpecable{
Spec: corev1.PodSpec{Tolerations: []corev1.Toleration{{Key: "key"}}},
},
}},
},
},
},
}, {
name: "different value for replicas other than 0",
in: &v1beta1.EventListener{
Expand All @@ -179,23 +116,6 @@ func TestEventListenerSetDefaults(t *testing.T) {
},
},
},
}, {
name: "different value for deprecated replicas other than 0",
in: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
DeprecatedReplicas: ptr.Int32(2),
},
},
wc: contexts.WithUpgradeViaDefaulting,
want: &v1beta1.EventListener{
Spec: v1beta1.EventListenerSpec{
Resources: v1beta1.Resources{
KubernetesResource: &v1beta1.KubernetesResource{
Replicas: ptr.Int32(2),
},
},
},
},
}, {
name: "adds interceptorkind when not specified",
in: &v1beta1.EventListener{
Expand Down
9 changes: 3 additions & 6 deletions pkg/apis/triggers/v1beta1/event_listener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ type EventListener struct {
type EventListenerSpec struct {
ServiceAccountName string `json:"serviceAccountName,omitempty"`
Triggers []EventListenerTrigger `json:"triggers"`
// To be removed in a later release #1020
DeprecatedReplicas *int32 `json:"replicas,omitempty"`
DeprecatedPodTemplate *PodTemplate `json:"podTemplate,omitempty"`
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
Resources Resources `json:"resources,omitempty"`
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
Resources Resources `json:"resources,omitempty"`
}

type Resources struct {
Expand Down
7 changes: 0 additions & 7 deletions pkg/apis/triggers/v1beta1/event_listener_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ func (s *EventListenerSpec) validate(ctx context.Context) (errs *apis.FieldError
errs = errs.Also(trigger.validate(ctx).ViaField(fmt.Sprintf("spec.triggers[%d]", i)))
}

// To be removed in a later release #1020
if s.DeprecatedReplicas != nil {
if *s.DeprecatedReplicas < 0 {
errs = errs.Also(apis.ErrInvalidValue(*s.DeprecatedReplicas, "spec.replicas"))
}
}

// Both Kubernetes and Custom resource can't be present at the same time
if s.Resources.KubernetesResource != nil && s.Resources.CustomResource != nil {
return apis.ErrMultipleOneOf("spec.resources.kubernetesResource", "spec.resources.customResource")
Expand Down
76 changes: 0 additions & 76 deletions pkg/apis/triggers/v1beta1/event_listener_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,81 +841,6 @@ func TestEventListenerValidate_error(t *testing.T) {
}},
},
},
}, {
name: "Multiple interceptors set",
el: &triggersv1beta1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: triggersv1beta1.EventListenerSpec{
Triggers: []triggersv1beta1.EventListenerTrigger{{
Bindings: []*triggersv1beta1.EventListenerBinding{{Kind: triggersv1beta1.NamespacedTriggerBindingKind, Ref: "tb"}},
Template: &triggersv1beta1.EventListenerTemplate{Ref: ptr.String("tt")},
Interceptors: []*triggersv1beta1.EventInterceptor{{
DeprecatedGitHub: &triggersv1beta1.GitHubInterceptor{},
DeprecatedGitLab: &triggersv1beta1.GitLabInterceptor{},
DeprecatedBitbucket: &triggersv1beta1.BitbucketInterceptor{},
}},
}},
},
},
}, {
name: "CEL interceptor with no filter or overlays",
el: &triggersv1beta1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: triggersv1beta1.EventListenerSpec{
Triggers: []triggersv1beta1.EventListenerTrigger{{
Bindings: []*triggersv1beta1.EventListenerBinding{{Kind: triggersv1beta1.NamespacedTriggerBindingKind, Ref: "tb"}},
Template: &triggersv1beta1.EventListenerTemplate{Ref: ptr.String("tt")},
Interceptors: []*triggersv1beta1.EventInterceptor{{
DeprecatedCEL: &triggersv1beta1.CELInterceptor{},
}},
}},
},
},
}, {
name: "CEL interceptor with bad filter expression",
el: &triggersv1beta1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: triggersv1beta1.EventListenerSpec{
Triggers: []triggersv1beta1.EventListenerTrigger{{
Interceptors: []*triggersv1beta1.EventInterceptor{{
DeprecatedCEL: &triggersv1beta1.CELInterceptor{
Filter: "body.value == 'test'",
},
}},
Template: &triggersv1beta1.EventListenerTemplate{Ref: ptr.String(""), APIVersion: "triggersv1beta1"},
}},
},
},
}, {
name: "CEL interceptor with bad overlay expression",
el: &triggersv1beta1.EventListener{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: triggersv1beta1.EventListenerSpec{
Triggers: []triggersv1beta1.EventListenerTrigger{{
Interceptors: []*triggersv1beta1.EventInterceptor{{
DeprecatedCEL: &triggersv1beta1.CELInterceptor{
Overlays: []triggersv1beta1.CELOverlay{{
Key: "value",
Expression: "'testing')",
}},
},
}},
Template: &triggersv1beta1.EventListenerTemplate{Ref: ptr.String(""), APIVersion: "triggersv1beta1"},
}},
},
},
}, {
name: "Triggers name has invalid label characters",
el: &triggersv1beta1.EventListener{
Expand Down Expand Up @@ -959,7 +884,6 @@ func TestEventListenerValidate_error(t *testing.T) {
Ref: ptr.String("tt"),
},
}},
DeprecatedReplicas: ptr.Int32(-1),
Resources: triggersv1beta1.Resources{
KubernetesResource: &triggersv1beta1.KubernetesResource{
Replicas: ptr.Int32(-1),
Expand Down
7 changes: 0 additions & 7 deletions pkg/apis/triggers/v1beta1/trigger_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"

"github.com/tektoncd/triggers/pkg/apis/triggers/contexts"
"knative.dev/pkg/logging"
)

type triggerSpecBindingArray []*TriggerSpecBinding
Expand All @@ -33,12 +32,6 @@ func (t *Trigger) SetDefaults(ctx context.Context) {
triggerSpecBindingArray(t.Spec.Bindings).defaultBindings()
for _, ti := range t.Spec.Interceptors {
ti.defaultInterceptorKind()
if err := ti.updateCoreInterceptors(); err != nil {
// The err only happens due to malformed JSON and should never really happen
// We can't return an error here, so print out the error
logger := logging.FromContext(ctx)
logger.Errorf("failed to setDefaults for trigger: %s; err: %s", t.Name, err)
}
}
}

Expand Down
Loading

0 comments on commit d7cb6f7

Please sign in to comment.