Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions charts/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,3 @@ data:
controller_name: {{ .Values.controllerName | default "gateway.api7.io/api7-ingress-controller" }}

leader_election_id: "api7-ingress-controller-leader"

gateway_configs:
- name: "api7ee"
control_plane:
admin_key: "{{ required "Provide a valid admin key!" .Values.admin.key }}"
endpoints:
- "{{ .Values.admin.endpoint }}"
tls_verify: {{ .Values.admin.tlsVerify }}
addresses: # record the status address of the gateway-api gateway
- "{{ .Values.statusAddress }}"
4 changes: 0 additions & 4 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func newAPI7IngressController() *cobra.Command {
cfg := config.ControllerConfig
var configPath string

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

if err := cfg.Validate(); err != nil {
Expand Down Expand Up @@ -153,7 +150,6 @@ func newAPI7IngressController() *cobra.Command {
cmd.Flags().StringVar(&cfg.MetricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
cmd.Flags().StringVar(&cfg.ProbeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
cmd.Flags().Var(&controlPlanesFlag, "control-planes", "Control planes configuration in YAML format")
cmd.Flags().StringVar(&cfg.LogLevel, "log-level", config.DefaultLogLevel, "The log level for api7-ingress-controller")
cmd.Flags().StringVar(&cfg.ControllerName,
"controller-name",
Expand Down
26 changes: 13 additions & 13 deletions config/samples/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
log_level: "info" # The log level of the API7 Ingress Controller.
log_level: "debug" # The log level of the API7 Ingress Controller.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info

# the default value is "info".

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

ingress_class: api7 # The ingress class name of the API7 Ingress Controller.
ingress_publish_service: "" # The service name of the ingress publish service.
ingress_status_address: [] # The status address of the ingress.
gateway_configs: # The configuration of the API7 Gateway.
- name: api7 # The name of the Gateway in the Gateway API.
control_plane:
admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
endpoints:
- ${ENDPOINT} # The endpoint of the control plane.
tls_verify: false
addresses: # record the status address of the gateway-api gateway
- "172.18.0.4" # The LB IP of the gateway service.
# ingress_class: api7 # The ingress class name of the API7 Ingress Controller.
# ingress_publish_service: "" # The service name of the ingress publish service.
# ingress_status_address: [] # The status address of the ingress.
# gateway_configs: # The configuration of the API7 Gateway.
# - name: api7 # The name of the Gateway in the Gateway API.
# control_plane:
# admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
# endpoints:
# - ${ENDPOINT} # The endpoint of the control plane.
# tls_verify: false
# addresses: # record the status address of the gateway-api gateway
# - "172.18.0.4" # The LB IP of the gateway service.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keep it?

Copy link
Contributor Author

@ronething ronething Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will resolve it in the next PR.

10 changes: 0 additions & 10 deletions docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ controller_name: gateway.api7.io/api7-ingress-controller # The controller name

leader_election_id: "api7-ingress-controller-leader" # The leader election ID for the API7 Ingress Controller.
# The default value is "api7-ingress-controller-leader".

gateway_configs: # The configuration of the API7 Gateway.
- name: api7 # The name of the Gateway in the Gateway API.
control_plane:
admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
endpoints:
- ${ENDPOINT}/apisix/admin # The endpoint of the control plane.
tls_verify: false
addresses: # record the status address of the gateway-api gateway
- "172.18.0.4" # The LB IP of the gateway service.
```

### Controller Name
Expand Down
80 changes: 1 addition & 79 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func NewDefaultConfig() *Config {
LeaderElectionID: DefaultLeaderElectionID,
ProbeAddr: DefaultProbeAddr,
MetricsAddr: DefaultMetricsAddr,
IngressClass: DefaultIngressClass,
LeaderElection: NewLeaderElection(),
}
}
Expand Down Expand Up @@ -84,21 +83,13 @@ func NewConfigFromFile(filename string) (*Config, error) {
}

func (c *Config) Validate() error {

if len(c.GatewayConfigs) == 0 {
return fmt.Errorf("gateway_configs config is required")
}
for _, gc := range c.GatewayConfigs {
if err := c.validateGatewayConfig(gc); err != nil {
return fmt.Errorf("failed to validate control_planes: %w", err)
}
}
if c.ControllerName == "" {
return fmt.Errorf("controller_name is required")
}
return nil
}

//nolint:unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito.

func (c *Config) validateGatewayConfig(gc *GatewayConfig) error {

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

var gatewayNameMap map[string]*GatewayConfig
var gatewayNameList []string

func initGatewayNameMap() {
if gatewayNameMap == nil {
gatewayNameMap = make(map[string]*GatewayConfig)
for _, gc := range ControllerConfig.GatewayConfigs {
gatewayNameMap[gc.Name] = gc
}
}
}

func GetControlPlaneConfigByGatewatName(gatewatName string) *ControlPlaneConfig {
initGatewayNameMap()
if gc, ok := gatewayNameMap[gatewatName]; ok {
return gc.ControlPlane
}
return nil
}

func GetGatewayConfig(gatewayName string) *GatewayConfig {
initGatewayNameMap()
if gc, ok := gatewayNameMap[gatewayName]; ok {
return gc
}
return nil
}

func GetFirstGatewayConfig() *GatewayConfig {
if len(ControllerConfig.GatewayConfigs) > 0 {
return ControllerConfig.GatewayConfigs[0]
}
return nil
}

func GetGatewayAddresses(gatewayName string) []string {
initGatewayNameMap()
if gc, ok := gatewayNameMap[gatewayName]; ok {
return gc.Addresses
}
return nil
}

func GatewayConfigs() []*GatewayConfig {
return ControllerConfig.GatewayConfigs
}

func GatewayNameList() []string {
if gatewayNameList == nil {
gatewayNameList = make([]string, 0, len(ControllerConfig.GatewayConfigs))
for _, gc := range ControllerConfig.GatewayConfigs {
gatewayNameList = append(gatewayNameList, gc.Name)
}
}
return gatewayNameList
}

func GetIngressClass() string {
return ControllerConfig.IngressClass
}

func GetIngressPublishService() string {
return ControllerConfig.IngressPublishService
}

func GetIngressStatusAddress() []string {
return ControllerConfig.IngressStatusAddress
}

func GetControllerName() string {
return ControllerConfig.ControllerName
}
27 changes: 10 additions & 17 deletions internal/controller/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,23 @@ const (
// DefaultLogLevel is the default log level for apisix-ingress-controller.
DefaultLogLevel = "info"

// DefaultIngressClass is the default ingress class name for Ingress resources
DefaultIngressClass = "api7"

DefaultMetricsAddr = ":8080"
DefaultProbeAddr = ":8081"
)

// Config contains all config items which are necessary for
// apisix-ingress-controller's running.
type Config struct {
CertFilePath string `json:"cert_file" yaml:"cert_file"`
KeyFilePath string `json:"key_file" yaml:"key_file"`
LogLevel string `json:"log_level" yaml:"log_level"`
ControllerName string `json:"controller_name" yaml:"controller_name"`
LeaderElectionID string `json:"leader_election_id" yaml:"leader_election_id"`
GatewayConfigs []*GatewayConfig `json:"gateway_configs" yaml:"gateway_configs"`
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr"`
EnableHTTP2 bool `json:"enable_http2" yaml:"enable_http2"`
ProbeAddr string `json:"probe_addr" yaml:"probe_addr"`
SecureMetrics bool `json:"secure_metrics" yaml:"secure_metrics"`
IngressClass string `json:"ingress_class" yaml:"ingress_class"`
IngressPublishService string `json:"ingress_publish_service" yaml:"ingress_publish_service"`
IngressStatusAddress []string `json:"ingress_status_address" yaml:"ingress_status_address"`
LeaderElection *LeaderElection `json:"leader_election" yaml:"leader_election"`
CertFilePath string `json:"cert_file" yaml:"cert_file"`
KeyFilePath string `json:"key_file" yaml:"key_file"`
LogLevel string `json:"log_level" yaml:"log_level"`
ControllerName string `json:"controller_name" yaml:"controller_name"`
LeaderElectionID string `json:"leader_election_id" yaml:"leader_election_id"`
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr"`
EnableHTTP2 bool `json:"enable_http2" yaml:"enable_http2"`
ProbeAddr string `json:"probe_addr" yaml:"probe_addr"`
SecureMetrics bool `json:"secure_metrics" yaml:"secure_metrics"`
LeaderElection *LeaderElection `json:"leader_election" yaml:"leader_election"`
}

type GatewayConfig struct {
Expand Down
47 changes: 29 additions & 18 deletions internal/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"

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

cfg := config.GetFirstGatewayConfig()

var addrs []gatewayv1.GatewayStatusAddress

if len(gateway.Status.Addresses) != len(cfg.Addresses) {
for _, addr := range cfg.Addresses {
if addr == "" {
continue
}
addrs = append(addrs,
gatewayv1.GatewayStatusAddress{
Value: addr,
},
)
}
}

r.Log.Info("gateway has been accepted", "gateway", gateway.GetName())
type status struct {
status bool
Expand All @@ -119,6 +101,35 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
}

var addrs []gatewayv1.GatewayStatusAddress

rk := provider.ResourceKind{
Kind: gateway.Kind,
Namespace: gateway.Namespace,
Name: gateway.Name,
}

gatewayProxy, ok := tctx.GatewayProxies[rk]
if !ok {
acceptStatus = status{
status: false,
msg: "gateway proxy not found",
}
} else {
if len(gateway.Status.Addresses) != len(gatewayProxy.Spec.StatusAddress) {
for _, addr := range gatewayProxy.Spec.StatusAddress {
if addr == "" {
continue
}
addrs = append(addrs,
gatewayv1.GatewayStatusAddress{
Value: addr,
},
)
}
}
}

if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
acceptStatus = status{
status: false,
Expand Down
Loading
Loading