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
54 changes: 1 addition & 53 deletions api/adc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,6 @@ import (
"github.com/incubator4/go-resty-expr/expr"
)

const (
// HashOnVars means the hash scope is variable.
HashOnVars = "vars"
// HashOnVarsCombination means the hash scope is the
// variable combination.
HashOnVarsCombination = "vars_combinations"
// HashOnHeader means the hash scope is HTTP request
// headers.
HashOnHeader = "header"
// HashOnCookie means the hash scope is HTTP Cookie.
HashOnCookie = "cookie"
// HashOnConsumer means the hash scope is APISIX consumer.
HashOnConsumer = "consumer"

// LbRoundRobin is the round robin load balancer.
LBRoundRobin = "roundrobin"
// LbConsistentHash is the consistent hash load balancer.
LbConsistentHash = "chash"
// LbEwma is the ewma load balancer.
LbEwma = "ewma"
// LbLeaseConn is the least connection load balancer.
LbLeastConn = "least_conn"

// SchemeHTTP represents the HTTP protocol.
SchemeHTTP = "http"
// SchemeGRPC represents the GRPC protocol.
SchemeGRPC = "grpc"
// SchemeHTTPS represents the HTTPS protocol.
SchemeHTTPS = "https"
// SchemeGRPCS represents the GRPCS protocol.
SchemeGRPCS = "grpcs"
// SchemeTCP represents the TCP protocol.
SchemeTCP = "tcp"
// SchemeUDP represents the UDP protocol.
SchemeUDP = "udp"

// DefaultUpstreamTimeout represents the default connect,
// read and send timeout (in seconds) with upstreams.
DefaultUpstreamTimeout = 60

// PassHostPass represents pass option for pass_host Upstream settings.
PassHostPass = "pass"
// PassHostPass represents node option for pass_host Upstream settings.
PassHostNode = "node"
// PassHostPass represents rewrite option for pass_host Upstream settings.
PassHostRewrite = "rewrite"
)

const (
TypeRoute = "route"
TypeService = "service"
Expand Down Expand Up @@ -392,11 +344,7 @@ const (
type Scheme string

const (
Grpc Scheme = "grpc"
Grpcs Scheme = "grpcs"
Kafka Scheme = "kafka"
TLS Scheme = "tls"
UDP Scheme = "udp"
SchemeHTTP = "http"
)

type UpstreamType string
Expand Down
40 changes: 20 additions & 20 deletions internal/adc/cache/memdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ func (c *dbCache) Delete(obj any) error {

func (c *dbCache) InsertRoute(r *types.Route) error {
route := r.DeepCopy()
return c.insert("route", route)
return c.insert(types.TypeRoute, route)
}

func (c *dbCache) InsertSSL(ssl *types.SSL) error {
return c.insert("ssl", ssl.DeepCopy())
return c.insert(types.TypeSSL, ssl.DeepCopy())
}

func (c *dbCache) InsertService(u *types.Service) error {
return c.insert("service", u.DeepCopy())
return c.insert(types.TypeService, u.DeepCopy())
}

func (c *dbCache) InsertConsumer(consumer *types.Consumer) error {
return c.insert("consumer", consumer.DeepCopy())
return c.insert(types.TypeConsumer, consumer.DeepCopy())
}

func (c *dbCache) InsertGlobalRule(globalRule *types.GlobalRuleItem) error {
return c.insert("global_rule", globalRule.DeepCopy())
return c.insert(types.TypeGlobalRule, globalRule.DeepCopy())
}

func (c *dbCache) insert(table string, obj any) error {
Expand All @@ -111,39 +111,39 @@ func (c *dbCache) insert(table string, obj any) error {
}

func (c *dbCache) GetRoute(id string) (*types.Route, error) {
obj, err := c.get("route", id)
obj, err := c.get(types.TypeRoute, id)
if err != nil {
return nil, err
}
return obj.(*types.Route).DeepCopy(), nil
}

func (c *dbCache) GetSSL(id string) (*types.SSL, error) {
obj, err := c.get("ssl", id)
obj, err := c.get(types.TypeSSL, id)
if err != nil {
return nil, err
}
return obj.(*types.SSL).DeepCopy(), nil
}

func (c *dbCache) GetService(id string) (*types.Service, error) {
obj, err := c.get("service", id)
obj, err := c.get(types.TypeService, id)
if err != nil {
return nil, err
}
return obj.(*types.Service).DeepCopy(), nil
}

func (c *dbCache) GetConsumer(username string) (*types.Consumer, error) {
obj, err := c.get("consumer", username)
obj, err := c.get(types.TypeConsumer, username)
if err != nil {
return nil, err
}
return obj.(*types.Consumer).DeepCopy(), nil
}

func (c *dbCache) GetGlobalRule(id string) (*types.GlobalRuleItem, error) {
obj, err := c.get("global_rule", id)
obj, err := c.get(types.TypeGlobalRule, id)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (c *dbCache) get(table, id string) (any, error) {
}

func (c *dbCache) ListRoutes(opts ...ListOption) ([]*types.Route, error) {
raws, err := c.list("route", opts...)
raws, err := c.list(types.TypeRoute, opts...)
if err != nil {
return nil, err
}
Expand All @@ -187,7 +187,7 @@ func (c *dbCache) ListRoutes(opts ...ListOption) ([]*types.Route, error) {
}

func (c *dbCache) ListSSL(opts ...ListOption) ([]*types.SSL, error) {
raws, err := c.list("ssl", opts...)
raws, err := c.list(types.TypeSSL, opts...)
if err != nil {
return nil, err
}
Expand All @@ -199,7 +199,7 @@ func (c *dbCache) ListSSL(opts ...ListOption) ([]*types.SSL, error) {
}

func (c *dbCache) ListServices(opts ...ListOption) ([]*types.Service, error) {
raws, err := c.list("service", opts...)
raws, err := c.list(types.TypeService, opts...)
if err != nil {
return nil, err
}
Expand All @@ -211,7 +211,7 @@ func (c *dbCache) ListServices(opts ...ListOption) ([]*types.Service, error) {
}

func (c *dbCache) ListConsumers(opts ...ListOption) ([]*types.Consumer, error) {
raws, err := c.list("consumer", opts...)
raws, err := c.list(types.TypeConsumer, opts...)
if err != nil {
return nil, err
}
Expand All @@ -223,7 +223,7 @@ func (c *dbCache) ListConsumers(opts ...ListOption) ([]*types.Consumer, error) {
}

func (c *dbCache) ListGlobalRules(opts ...ListOption) ([]*types.GlobalRuleItem, error) {
raws, err := c.list("global_rule", opts...)
raws, err := c.list(types.TypeGlobalRule, opts...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -257,23 +257,23 @@ func (c *dbCache) list(table string, opts ...ListOption) ([]any, error) {
}

func (c *dbCache) DeleteRoute(r *types.Route) error {
return c.delete("route", r)
return c.delete(types.TypeRoute, r)
}

func (c *dbCache) DeleteSSL(ssl *types.SSL) error {
return c.delete("ssl", ssl)
return c.delete(types.TypeSSL, ssl)
}

func (c *dbCache) DeleteService(u *types.Service) error {
return c.delete("service", u)
return c.delete(types.TypeService, u)
}

func (c *dbCache) DeleteConsumer(consumer *types.Consumer) error {
return c.delete("consumer", consumer)
return c.delete(types.TypeConsumer, consumer)
}

func (c *dbCache) DeleteGlobalRule(globalRule *types.GlobalRuleItem) error {
return c.delete("global_rule", globalRule)
return c.delete(types.TypeGlobalRule, globalRule)
}

func (c *dbCache) delete(table string, obj any) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/adc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (c *Client) sync(ctx context.Context, task Task) error {
pkgmetrics.RecordFileIODuration("prepare_sync_file", "failure", time.Since(fileIOStart).Seconds())
return err
}
pkgmetrics.RecordFileIODuration("prepare_sync_file", "success", time.Since(fileIOStart).Seconds())
pkgmetrics.RecordFileIODuration("prepare_sync_file", adctypes.StatusSuccess, time.Since(fileIOStart).Seconds())
defer cleanup()

args := BuildADCExecuteArgs(syncFilePath, task.Labels, task.ResourceTypes)
Expand All @@ -319,7 +319,7 @@ func (c *Client) sync(ctx context.Context, task Task) error {
err := c.executor.Execute(ctx, c.BackendMode, config, args)
duration := time.Since(startTime).Seconds()

status := "success"
status := adctypes.StatusSuccess
if err != nil {
status = "failure"
log.Errorw("failed to execute adc command", zap.Error(err), zap.Any("config", config))
Expand Down
3 changes: 2 additions & 1 deletion internal/adc/translator/apisixroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
apiv2 "github.com/apache/apisix-ingress-controller/api/v2"
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
"github.com/apache/apisix-ingress-controller/pkg/id"
pkgutils "github.com/apache/apisix-ingress-controller/pkg/utils"
Expand Down Expand Up @@ -405,7 +406,7 @@ func (t *Translator) translateApisixRouteBackendResolveGranularityEndpoint(tctx
backendRef := gatewayv1.BackendRef{
BackendObjectReference: gatewayv1.BackendObjectReference{
Group: (*gatewayv1.Group)(&apiv2.GroupVersion.Group),
Kind: (*gatewayv1.Kind)(ptr.To("Service")),
Kind: (*gatewayv1.Kind)(ptr.To(internaltypes.KindService)),
Name: gatewayv1.ObjectName(backend.ServiceName),
Namespace: (*gatewayv1.Namespace)(&arNN.Namespace),
Port: (*gatewayv1.PortNumber)(&port),
Expand Down
3 changes: 2 additions & 1 deletion internal/adc/translator/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/id"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ func (t *Translator) translateSecret(tctx *provider.TranslateContext, listener g
if ref.Namespace != nil {
ns = string(*ref.Namespace)
}
if listener.TLS.CertificateRefs[0].Kind != nil && *listener.TLS.CertificateRefs[0].Kind == "Secret" {
if listener.TLS.CertificateRefs[0].Kind != nil && *listener.TLS.CertificateRefs[0].Kind == internaltypes.KindSecret {
sslObj := &adctypes.SSL{
Snis: []string{},
}
Expand Down
9 changes: 5 additions & 4 deletions internal/adc/translator/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/id"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
)

func (t *Translator) fillPluginsFromHTTPRouteFilters(
Expand Down Expand Up @@ -70,7 +71,7 @@ func (t *Translator) fillPluginFromExtensionRef(plugins adctypes.Plugins, namesp
if extensionRef == nil {
return
}
if extensionRef.Kind == "PluginConfig" {
if extensionRef.Kind == internaltypes.KindPluginConfig {
pluginconfig := tctx.PluginConfigs[types.NamespacedName{
Namespace: namespace,
Name: string(extensionRef.Name),
Expand Down Expand Up @@ -300,7 +301,7 @@ func (t *Translator) fillHTTPRoutePoliciesForHTTPRoute(tctx *provider.TranslateC
var policies []v1alpha1.HTTPRoutePolicy
for _, policy := range tctx.HTTPRoutePolicies {
for _, ref := range policy.Spec.TargetRefs {
if string(ref.Kind) == "HTTPRoute" && (ref.SectionName == nil || *ref.SectionName == "" || ptr.Equal(ref.SectionName, rule.Name)) {
if string(ref.Kind) == internaltypes.KindHTTPRoute && (ref.SectionName == nil || *ref.SectionName == "" || ptr.Equal(ref.SectionName, rule.Name)) {
policies = append(policies, policy)
break
}
Expand Down Expand Up @@ -376,7 +377,7 @@ func (t *Translator) TranslateBackendRefWithFilter(tctx *provider.TranslateConte
}

func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref gatewayv1.BackendRef, endpointFilter func(*discoveryv1.Endpoint) bool) (adctypes.UpstreamNodes, error) {
if ref.Kind != nil && *ref.Kind != "Service" {
if ref.Kind != nil && *ref.Kind != internaltypes.KindService {
return adctypes.UpstreamNodes{}, fmt.Errorf("kind %s is not supported", *ref.Kind)
}

Expand Down Expand Up @@ -549,7 +550,7 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou
port int32
)
if backend.Kind == nil {
kind = "Service"
kind = internaltypes.KindService
} else {
kind = string(*backend.Kind)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/adc/translator/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/controller/label"
"github.com/apache/apisix-ingress-controller/internal/id"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
)

func (t *Translator) translateIngressTLS(ingressTLS *networkingv1.IngressTLS, secret *corev1.Secret, labels map[string]string) (*adctypes.SSL, error) {
Expand Down Expand Up @@ -123,7 +124,7 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
// get the EndpointSlice of the backend service
backendService := path.Backend.Service
if backendService != nil {
backendRef := convertBackendRef(obj.Namespace, backendService.Name, "Service")
backendRef := convertBackendRef(obj.Namespace, backendService.Name, internaltypes.KindService)
t.AttachBackendTrafficPolicyToUpstream(backendRef, tctx.BackendTrafficPolicies, upstream)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/apisixroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (r *ApisixRouteReconciler) validateHTTPBackend(tctx *provider.TranslateCont
return nil
}

if backend.ResolveGranularity == "service" && service.Spec.ClusterIP == "" {
if backend.ResolveGranularity == apiv2.ResolveGranularityService && service.Spec.ClusterIP == "" {
r.Log.Error(errors.New("service has no ClusterIP"), "Service", serviceNN, "ResolveGranularity", backend.ResolveGranularity)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/consumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/controller/status"
"github.com/apache/apisix-ingress-controller/internal/manager/readiness"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
)

Expand Down Expand Up @@ -193,7 +194,7 @@ func (r *ConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
consumer.Name = req.Name

consumer.TypeMeta = metav1.TypeMeta{
Kind: "Consumer",
Kind: internaltypes.KindConsumer,
APIVersion: v1alpha1.GroupVersion.String(),
}

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/apache/apisix-ingress-controller/internal/controller/indexer"
"github.com/apache/apisix-ingress-controller/internal/controller/status"
"github.com/apache/apisix-ingress-controller/internal/provider"
internaltypes "github.com/apache/apisix-ingress-controller/internal/types"
"github.com/apache/apisix-ingress-controller/internal/utils"
)

Expand Down Expand Up @@ -316,7 +317,7 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(ctx context.Context, obj cl
if parentRef.Group != nil && *parentRef.Group != gatewayv1.GroupName {
continue
}
if parentRef.Kind != nil && *parentRef.Kind != "Gateway" {
if parentRef.Kind != nil && *parentRef.Kind != internaltypes.KindGateway {
continue
}
if parentRef.Namespace != nil {
Expand Down
Loading
Loading