Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ dist
.tmp
api7-ingress-controller
api7-ingress-controller-conformance-report.yaml

*.mdx
4 changes: 2 additions & 2 deletions api/adc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,6 @@ type ResponseDetails struct {
}

type ResponseData struct {
Value map[string]interface{} `json:"value"`
ErrorMsg string `json:"error_msg"`
Value map[string]any `json:"value"`
ErrorMsg string `json:"error_msg"`
}
24 changes: 24 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,27 @@ rules:
verbs:
- get
- update
- apiGroups:
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingresses
verbs:
- get
- list
- update
- watch
- apiGroups:
- networking.k8s.io
resources:
- ingresses/status
verbs:
- get
- update
4 changes: 4 additions & 0 deletions config/samples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ 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".

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:
Expand Down
17 changes: 17 additions & 0 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewDefaultConfig() *Config {
LeaderElectionID: DefaultLeaderElectionID,
ProbeAddr: DefaultProbeAddr,
MetricsAddr: DefaultMetricsAddr,
IngressClass: DefaultIngressClass,
}
}

Expand Down Expand Up @@ -161,3 +162,19 @@ func GatewayNameList() []string {
}
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
}
26 changes: 16 additions & 10 deletions internal/controller/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,29 @@ 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"`
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"`
}

type GatewayConfig struct {
Expand Down
103 changes: 103 additions & 0 deletions internal/controller/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (
"context"

networkingv1 "k8s.io/api/networking/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
Expand All @@ -13,6 +14,9 @@ const (
ExtensionRef = "extensionRef"
ParametersRef = "parametersRef"
ParentRefs = "parentRefs"
IngressClass = "ingressClass"
SecretIndexRef = "secretRefs"
IngressClassRef = "ingressClassRef"
)

func SetupIndexer(mgr ctrl.Manager) error {
Expand All @@ -22,6 +26,9 @@ func SetupIndexer(mgr ctrl.Manager) error {
if err := setupHTTPRouteIndexer(mgr); err != nil {
return err
}
if err := setupIngressIndexer(mgr); err != nil {
return err
}
return nil
}

Expand Down Expand Up @@ -67,6 +74,102 @@ func setupHTTPRouteIndexer(mgr ctrl.Manager) error {
return nil
}

func setupIngressIndexer(mgr ctrl.Manager) error {
// create IngressClass index
if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&networkingv1.Ingress{},
IngressClassRef,
IngressClassRefIndexFunc,
); err != nil {
return err
}

// create Service index for quick lookup of Ingresses using specific services
if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&networkingv1.Ingress{},
ServiceIndexRef,
IngressServiceIndexFunc,
); err != nil {
return err
}

// create secret index for TLS
if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&networkingv1.Ingress{},
SecretIndexRef,
IngressSecretIndexFunc,
); err != nil {
return err
}

// create IngressClass index
if err := mgr.GetFieldIndexer().IndexField(
context.Background(),
&networkingv1.IngressClass{},
IngressClass,
IngressClassIndexFunc,
); err != nil {
return err
}

return nil
}

func IngressClassIndexFunc(rawObj client.Object) []string {
ingressClass := rawObj.(*networkingv1.IngressClass)
if ingressClass.Spec.Controller == "" {
return nil
}
controllerName := ingressClass.Spec.Controller
return []string{controllerName}
}

func IngressClassRefIndexFunc(rawObj client.Object) []string {
ingress := rawObj.(*networkingv1.Ingress)
if ingress.Spec.IngressClassName == nil {
return nil
}
return []string{*ingress.Spec.IngressClassName}
}

func IngressServiceIndexFunc(rawObj client.Object) []string {
ingress := rawObj.(*networkingv1.Ingress)
var services []string

for _, rule := range ingress.Spec.Rules {
if rule.HTTP == nil {
continue
}

for _, path := range rule.HTTP.Paths {
if path.Backend.Service == nil {
continue
}
key := GenIndexKey(ingress.Namespace, path.Backend.Service.Name)
services = append(services, key)
}
}
return services
}

func IngressSecretIndexFunc(rawObj client.Object) []string {
ingress := rawObj.(*networkingv1.Ingress)
secrets := make([]string, 0)

for _, tls := range ingress.Spec.TLS {
if tls.SecretName == "" {
continue
}

key := GenIndexKey(ingress.Namespace, tls.SecretName)
secrets = append(secrets, key)
}
return secrets
}

func GenIndexKey(namespace, name string) string {
return client.ObjectKey{
Namespace: namespace,
Expand Down
Loading
Loading