Skip to content

Commit c6f9a74

Browse files
authored
fix: remove gateway config items from the config file. (#96)
Signed-off-by: ashing <[email protected]>
1 parent cb81148 commit c6f9a74

File tree

20 files changed

+341
-313
lines changed

20 files changed

+341
-313
lines changed

charts/templates/configmap.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ data:
1010
controller_name: {{ .Values.controllerName | default "gateway.api7.io/api7-ingress-controller" }}
1111
1212
leader_election_id: "api7-ingress-controller-leader"
13-
14-
gateway_configs:
15-
- name: "api7ee"
16-
control_plane:
17-
admin_key: "{{ required "Provide a valid admin key!" .Values.admin.key }}"
18-
endpoints:
19-
- "{{ .Values.admin.endpoint }}"
20-
tls_verify: {{ .Values.admin.tlsVerify }}
21-
addresses: # record the status address of the gateway-api gateway
22-
- "{{ .Values.statusAddress }}"

cmd/root/root.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ func newAPI7IngressController() *cobra.Command {
9191
cfg := config.ControllerConfig
9292
var configPath string
9393

94-
var controlPlanesFlag GatewayConfigsFlag
9594
cmd := &cobra.Command{
9695
Use: "api7-ingress-controller [command]",
9796
Long: "Yet another Ingress controller for Kubernetes using api7ee Gateway as the high performance reverse proxy.",
@@ -104,8 +103,6 @@ func newAPI7IngressController() *cobra.Command {
104103
}
105104
cfg = c
106105
config.SetControllerConfig(c)
107-
} else {
108-
cfg.GatewayConfigs = controlPlanesFlag.GatewayConfigs
109106
}
110107

111108
if err := cfg.Validate(); err != nil {
@@ -153,7 +150,6 @@ func newAPI7IngressController() *cobra.Command {
153150
cmd.Flags().StringVar(&cfg.MetricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
154151
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
155152
cmd.Flags().StringVar(&cfg.ProbeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
156-
cmd.Flags().Var(&controlPlanesFlag, "control-planes", "Control planes configuration in YAML format")
157153
cmd.Flags().StringVar(&cfg.LogLevel, "log-level", config.DefaultLogLevel, "The log level for api7-ingress-controller")
158154
cmd.Flags().StringVar(&cfg.ControllerName,
159155
"controller-name",

config/samples/config.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
log_level: "info" # The log level of the API7 Ingress Controller.
1+
log_level: "debug" # The log level of the API7 Ingress Controller.
22
# the default value is "info".
33

44
controller_name: gateway.api7.io/api7-ingress-controller # The controller name of the API7 Ingress Controller,
@@ -16,15 +16,15 @@ leader_election:
1616
# will wait between tries of actions with the controller.
1717
disable: false # Whether to disable leader election.
1818

19-
ingress_class: api7 # The ingress class name of the API7 Ingress Controller.
20-
ingress_publish_service: "" # The service name of the ingress publish service.
21-
ingress_status_address: [] # The status address of the ingress.
22-
gateway_configs: # The configuration of the API7 Gateway.
23-
- name: api7 # The name of the Gateway in the Gateway API.
24-
control_plane:
25-
admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
26-
endpoints:
27-
- ${ENDPOINT} # The endpoint of the control plane.
28-
tls_verify: false
29-
addresses: # record the status address of the gateway-api gateway
30-
- "172.18.0.4" # The LB IP of the gateway service.
19+
# ingress_class: api7 # The ingress class name of the API7 Ingress Controller.
20+
# ingress_publish_service: "" # The service name of the ingress publish service.
21+
# ingress_status_address: [] # The status address of the ingress.
22+
# gateway_configs: # The configuration of the API7 Gateway.
23+
# - name: api7 # The name of the Gateway in the Gateway API.
24+
# control_plane:
25+
# admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
26+
# endpoints:
27+
# - ${ENDPOINT} # The endpoint of the control plane.
28+
# tls_verify: false
29+
# addresses: # record the status address of the gateway-api gateway
30+
# - "172.18.0.4" # The LB IP of the gateway service.

docs/configure.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ controller_name: gateway.api7.io/api7-ingress-controller # The controller name
1414

1515
leader_election_id: "api7-ingress-controller-leader" # The leader election ID for the API7 Ingress Controller.
1616
# The default value is "api7-ingress-controller-leader".
17-
18-
gateway_configs: # The configuration of the API7 Gateway.
19-
- name: api7 # The name of the Gateway in the Gateway API.
20-
control_plane:
21-
admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
22-
endpoints:
23-
- ${ENDPOINT}/apisix/admin # The endpoint of the control plane.
24-
tls_verify: false
25-
addresses: # record the status address of the gateway-api gateway
26-
- "172.18.0.4" # The LB IP of the gateway service.
2717
```
2818

2919
### Controller Name

internal/controller/config/config.go

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func NewDefaultConfig() *Config {
3030
LeaderElectionID: DefaultLeaderElectionID,
3131
ProbeAddr: DefaultProbeAddr,
3232
MetricsAddr: DefaultMetricsAddr,
33-
IngressClass: DefaultIngressClass,
3433
LeaderElection: NewLeaderElection(),
3534
}
3635
}
@@ -84,21 +83,13 @@ func NewConfigFromFile(filename string) (*Config, error) {
8483
}
8584

8685
func (c *Config) Validate() error {
87-
88-
if len(c.GatewayConfigs) == 0 {
89-
return fmt.Errorf("gateway_configs config is required")
90-
}
91-
for _, gc := range c.GatewayConfigs {
92-
if err := c.validateGatewayConfig(gc); err != nil {
93-
return fmt.Errorf("failed to validate control_planes: %w", err)
94-
}
95-
}
9686
if c.ControllerName == "" {
9787
return fmt.Errorf("controller_name is required")
9888
}
9989
return nil
10090
}
10191

92+
//nolint:unused
10293
func (c *Config) validateGatewayConfig(gc *GatewayConfig) error {
10394

10495
if gc.Name == "" {
@@ -118,75 +109,6 @@ func (c *Config) validateGatewayConfig(gc *GatewayConfig) error {
118109
return nil
119110
}
120111

121-
var gatewayNameMap map[string]*GatewayConfig
122-
var gatewayNameList []string
123-
124-
func initGatewayNameMap() {
125-
if gatewayNameMap == nil {
126-
gatewayNameMap = make(map[string]*GatewayConfig)
127-
for _, gc := range ControllerConfig.GatewayConfigs {
128-
gatewayNameMap[gc.Name] = gc
129-
}
130-
}
131-
}
132-
133-
func GetControlPlaneConfigByGatewatName(gatewatName string) *ControlPlaneConfig {
134-
initGatewayNameMap()
135-
if gc, ok := gatewayNameMap[gatewatName]; ok {
136-
return gc.ControlPlane
137-
}
138-
return nil
139-
}
140-
141-
func GetGatewayConfig(gatewayName string) *GatewayConfig {
142-
initGatewayNameMap()
143-
if gc, ok := gatewayNameMap[gatewayName]; ok {
144-
return gc
145-
}
146-
return nil
147-
}
148-
149-
func GetFirstGatewayConfig() *GatewayConfig {
150-
if len(ControllerConfig.GatewayConfigs) > 0 {
151-
return ControllerConfig.GatewayConfigs[0]
152-
}
153-
return nil
154-
}
155-
156-
func GetGatewayAddresses(gatewayName string) []string {
157-
initGatewayNameMap()
158-
if gc, ok := gatewayNameMap[gatewayName]; ok {
159-
return gc.Addresses
160-
}
161-
return nil
162-
}
163-
164-
func GatewayConfigs() []*GatewayConfig {
165-
return ControllerConfig.GatewayConfigs
166-
}
167-
168-
func GatewayNameList() []string {
169-
if gatewayNameList == nil {
170-
gatewayNameList = make([]string, 0, len(ControllerConfig.GatewayConfigs))
171-
for _, gc := range ControllerConfig.GatewayConfigs {
172-
gatewayNameList = append(gatewayNameList, gc.Name)
173-
}
174-
}
175-
return gatewayNameList
176-
}
177-
178-
func GetIngressClass() string {
179-
return ControllerConfig.IngressClass
180-
}
181-
182-
func GetIngressPublishService() string {
183-
return ControllerConfig.IngressPublishService
184-
}
185-
186-
func GetIngressStatusAddress() []string {
187-
return ControllerConfig.IngressStatusAddress
188-
}
189-
190112
func GetControllerName() string {
191113
return ControllerConfig.ControllerName
192114
}

internal/controller/config/types.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,23 @@ const (
1717
// DefaultLogLevel is the default log level for apisix-ingress-controller.
1818
DefaultLogLevel = "info"
1919

20-
// DefaultIngressClass is the default ingress class name for Ingress resources
21-
DefaultIngressClass = "api7"
22-
2320
DefaultMetricsAddr = ":8080"
2421
DefaultProbeAddr = ":8081"
2522
)
2623

2724
// Config contains all config items which are necessary for
2825
// apisix-ingress-controller's running.
2926
type Config struct {
30-
CertFilePath string `json:"cert_file" yaml:"cert_file"`
31-
KeyFilePath string `json:"key_file" yaml:"key_file"`
32-
LogLevel string `json:"log_level" yaml:"log_level"`
33-
ControllerName string `json:"controller_name" yaml:"controller_name"`
34-
LeaderElectionID string `json:"leader_election_id" yaml:"leader_election_id"`
35-
GatewayConfigs []*GatewayConfig `json:"gateway_configs" yaml:"gateway_configs"`
36-
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr"`
37-
EnableHTTP2 bool `json:"enable_http2" yaml:"enable_http2"`
38-
ProbeAddr string `json:"probe_addr" yaml:"probe_addr"`
39-
SecureMetrics bool `json:"secure_metrics" yaml:"secure_metrics"`
40-
IngressClass string `json:"ingress_class" yaml:"ingress_class"`
41-
IngressPublishService string `json:"ingress_publish_service" yaml:"ingress_publish_service"`
42-
IngressStatusAddress []string `json:"ingress_status_address" yaml:"ingress_status_address"`
43-
LeaderElection *LeaderElection `json:"leader_election" yaml:"leader_election"`
27+
CertFilePath string `json:"cert_file" yaml:"cert_file"`
28+
KeyFilePath string `json:"key_file" yaml:"key_file"`
29+
LogLevel string `json:"log_level" yaml:"log_level"`
30+
ControllerName string `json:"controller_name" yaml:"controller_name"`
31+
LeaderElectionID string `json:"leader_election_id" yaml:"leader_election_id"`
32+
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr"`
33+
EnableHTTP2 bool `json:"enable_http2" yaml:"enable_http2"`
34+
ProbeAddr string `json:"probe_addr" yaml:"probe_addr"`
35+
SecureMetrics bool `json:"secure_metrics" yaml:"secure_metrics"`
36+
LeaderElection *LeaderElection `json:"leader_election" yaml:"leader_election"`
4437
}
4538

4639
type GatewayConfig struct {

internal/controller/gateway_controller.go

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"reflect"
77

88
"github.com/api7/api7-ingress-controller/api/v1alpha1"
9-
"github.com/api7/api7-ingress-controller/internal/controller/config"
109
"github.com/api7/api7-ingress-controller/internal/controller/indexer"
1110
"github.com/api7/api7-ingress-controller/internal/provider"
1211
"github.com/api7/gopkg/pkg/log"
@@ -81,23 +80,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
8180
}
8281
conditionProgrammedStatus, conditionProgrammedMsg := true, "Programmed"
8382

84-
cfg := config.GetFirstGatewayConfig()
85-
86-
var addrs []gatewayv1.GatewayStatusAddress
87-
88-
if len(gateway.Status.Addresses) != len(cfg.Addresses) {
89-
for _, addr := range cfg.Addresses {
90-
if addr == "" {
91-
continue
92-
}
93-
addrs = append(addrs,
94-
gatewayv1.GatewayStatusAddress{
95-
Value: addr,
96-
},
97-
)
98-
}
99-
}
100-
10183
r.Log.Info("gateway has been accepted", "gateway", gateway.GetName())
10284
type status struct {
10385
status bool
@@ -119,6 +101,35 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
119101
}
120102
}
121103

104+
var addrs []gatewayv1.GatewayStatusAddress
105+
106+
rk := provider.ResourceKind{
107+
Kind: gateway.Kind,
108+
Namespace: gateway.Namespace,
109+
Name: gateway.Name,
110+
}
111+
112+
gatewayProxy, ok := tctx.GatewayProxies[rk]
113+
if !ok {
114+
acceptStatus = status{
115+
status: false,
116+
msg: "gateway proxy not found",
117+
}
118+
} else {
119+
if len(gateway.Status.Addresses) != len(gatewayProxy.Spec.StatusAddress) {
120+
for _, addr := range gatewayProxy.Spec.StatusAddress {
121+
if addr == "" {
122+
continue
123+
}
124+
addrs = append(addrs,
125+
gatewayv1.GatewayStatusAddress{
126+
Value: addr,
127+
},
128+
)
129+
}
130+
}
131+
}
132+
122133
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
123134
acceptStatus = status{
124135
status: false,

0 commit comments

Comments
 (0)