-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebhook_validation.go
More file actions
117 lines (102 loc) · 3.86 KB
/
webhook_validation.go
File metadata and controls
117 lines (102 loc) · 3.86 KB
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 controller
import (
"context"
"github.com/go-logr/logr"
networkingv1 "k8s.io/api/networking/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
v1alpha1 "github.com/apache/apisix-ingress-controller/api/v1alpha1"
apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
"github.com/apache/apisix-ingress-controller/internal/provider"
"github.com/apache/apisix-ingress-controller/internal/utils"
)
func PrepareApisixRouteForValidation(ctx context.Context, c client.Client, log logr.Logger, route *apiv2.ApisixRoute) (*provider.TranslateContext, error) {
tctx := provider.NewDefaultTranslateContext(ctx)
ingressClass, err := FindMatchingIngressClassByObject(tctx, c, log, route, networkingv1.SchemeGroupVersion.String())
if err != nil {
return nil, err
}
if err := ProcessIngressClassParameters(tctx, c, log, route, ingressClass); err != nil {
return nil, err
}
reconciler := &ApisixRouteReconciler{
Client: c,
Log: log,
ICGV: networkingv1.SchemeGroupVersion,
supportsEndpointSlice: false,
}
if err := reconciler.processApisixRoute(tctx, route); err != nil {
return nil, err
}
return tctx, nil
}
func PrepareApisixConsumerForValidation(ctx context.Context, c client.Client, log logr.Logger, consumer *apiv2.ApisixConsumer) (*provider.TranslateContext, error) {
tctx := provider.NewDefaultTranslateContext(ctx)
ingressClass, err := FindMatchingIngressClassByObject(tctx, c, log, consumer, networkingv1.SchemeGroupVersion.String())
if err != nil {
return nil, err
}
if err := ProcessIngressClassParameters(tctx, c, log, consumer, ingressClass); err != nil {
return nil, err
}
reconciler := &ApisixConsumerReconciler{
Client: c,
Log: log,
ICGV: networkingv1.SchemeGroupVersion,
}
if err := reconciler.processSpec(ctx, tctx, consumer); err != nil {
return nil, err
}
return tctx, nil
}
func PrepareConsumerForValidation(ctx context.Context, c client.Client, log logr.Logger, consumer *v1alpha1.Consumer) (*provider.TranslateContext, error) {
tctx := provider.NewDefaultTranslateContext(ctx)
reconciler := &ConsumerReconciler{
Client: c,
Log: log,
}
gateway, err := reconciler.getGateway(ctx, consumer)
if err != nil {
return nil, err
}
if err := ProcessGatewayProxy(c, log, tctx, gateway, utils.NamespacedNameKind(consumer)); err != nil {
return nil, err
}
if err := reconciler.processSpec(ctx, tctx, consumer); err != nil {
return nil, err
}
return tctx, nil
}
func PrepareApisixTlsForValidation(ctx context.Context, c client.Client, log logr.Logger, tls *apiv2.ApisixTls) (*provider.TranslateContext, error) {
tctx := provider.NewDefaultTranslateContext(ctx)
ingressClass, err := FindMatchingIngressClassByObject(tctx, c, log, tls, networkingv1.SchemeGroupVersion.String())
if err != nil {
return nil, err
}
if err := ProcessIngressClassParameters(tctx, c, log, tls, ingressClass); err != nil {
return nil, err
}
reconciler := &ApisixTlsReconciler{
Client: c,
Log: log,
}
if err := reconciler.processApisixTls(ctx, tctx, tls); err != nil {
return nil, err
}
return tctx, nil
}