Skip to content

Commit 9a6f08e

Browse files
committed
feat(standalone): support apisix-standalone for adc
1 parent 4ee0e26 commit 9a6f08e

File tree

23 files changed

+680
-151
lines changed

23 files changed

+680
-151
lines changed

Dockerfile.dev

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG ENABLE_PROXY=false
33
FROM node:22 AS node_builder
44

55
ARG TARGETARCH
6-
ARG ADC_COMMIT=78484e87a0168e0f86d130bfae8f808d0d1a1e41
6+
ARG ADC_COMMIT=2449ca81e3c61169f8c1e59efb4c1173a766bce2
77

88
WORKDIR /app
99

@@ -22,10 +22,13 @@ RUN apt update \
2222
&& rm -rf /app
2323

2424
FROM debian:bullseye-slim
25+
26+
ARG TARGETARCH
27+
2528
WORKDIR /app
2629

2730
COPY --from=node_builder /bin/adc /bin/adc
28-
COPY ./bin/apisix-ingress-controller .
31+
COPY ./bin/apisix-ingress-controller_${TARGETARCH} ./apisix-ingress-controller
2932
COPY ./config/samples/config.yaml ./conf/config.yaml
3033

3134
ENTRYPOINT ["/app/apisix-ingress-controller"]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ linux-build:
185185
.PHONY: build-image
186186
build-image: docker-build
187187

188+
.PHONY: build-image-with-adc-dev
189+
build-image-with-adc-dev:
190+
$(CONTAINER_TOOL) build -t ${IMG} -f Dockerfile.dev .
191+
188192
.PHONY: build-push-image
189193
build-push-image: docker-build
190194
@docker push ${IMG}

api/v1alpha1/consumer_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ type Consumer struct {
2525

2626
// ConsumerSpec defines the configuration for a consumer, including consumer name,
2727
// authentication credentials, and plugin settings.
28-
Spec ConsumerSpec `json:"spec,omitempty"`
29-
Status Status `json:"status,omitempty"`
28+
Spec ConsumerSpec `json:"spec,omitempty"`
29+
Status ConsumerStatus `json:"status,omitempty"`
3030
}
3131

32+
type ConsumerStatus struct {
33+
Status `json:",inline"`
34+
}
3235
type ConsumerSpec struct {
3336
// GatewayRef specifies the gateway details.
3437
GatewayRef GatewayRef `json:"gatewayRef,omitempty"`

api/v1alpha1/gatewayproxy_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type ControlPlaneProvider struct {
117117
// +kubebuilder:validation:MinItems=1
118118
Endpoints []string `json:"endpoints"`
119119

120+
Service *ProviderService `json:"service,omitempty"`
120121
// TlsVerify specifies whether to verify the TLS certificate of the control plane.
121122
// +optional
122123
TlsVerify *bool `json:"tlsVerify,omitempty"`
@@ -126,6 +127,14 @@ type ControlPlaneProvider struct {
126127
Auth ControlPlaneAuth `json:"auth"`
127128
}
128129

130+
type ProviderService struct {
131+
Name string `json:"name"`
132+
133+
// +kubebuilder:validation:Minimum=1
134+
// +kubebuilder:validation:Maximum=65535
135+
Port int32 `json:"port,omitempty"`
136+
}
137+
129138
// +kubebuilder:object:root=true
130139
// GatewayProxy is the Schema for the gatewayproxies API.
131140
type GatewayProxy struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apisix.apache.org_gatewayproxies.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ spec:
119119
type: string
120120
minItems: 1
121121
type: array
122+
service:
123+
properties:
124+
name:
125+
type: string
126+
port:
127+
format: int32
128+
maximum: 65535
129+
minimum: 1
130+
type: integer
131+
required:
132+
- name
133+
type: object
122134
tlsVerify:
123135
description: TlsVerify specifies whether to verify the TLS
124136
certificate of the control plane.

config/samples/config.yaml

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

44
controller_name: apisix.apache.org/apisix-ingress-controller # The controller name of the APISIX Ingress Controller,
@@ -32,6 +32,8 @@ exec_adc_timeout: 15s # The timeout for the ADC to execute.
3232
# The default value is 15 seconds.
3333

3434
provider:
35+
type: "api7ee"
36+
3537
sync_period: 0s
3638
# The period between two consecutive syncs.
3739
# The default value is 0 seconds, which means the controller will not sync.

internal/controller/config/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func NewDefaultConfig() *Config {
4646
LeaderElection: NewLeaderElection(),
4747
ExecADCTimeout: types.TimeDuration{Duration: 15 * time.Second},
4848
ProviderConfig: ProviderConfig{
49+
Type: ProviderTypeStandalone,
4950
SyncPeriod: types.TimeDuration{Duration: 0},
5051
InitSyncDelay: types.TimeDuration{Duration: 20 * time.Minute},
5152
},
@@ -104,9 +105,21 @@ func (c *Config) Validate() error {
104105
if c.ControllerName == "" {
105106
return fmt.Errorf("controller_name is required")
106107
}
108+
if err := validateProviderType(c.ProviderConfig.Type); err != nil {
109+
return err
110+
}
107111
return nil
108112
}
109113

114+
func validateProviderType(providerType ProviderType) error {
115+
switch providerType {
116+
case ProviderTypeStandalone, ProviderTypeAPI7EE:
117+
return nil
118+
default:
119+
return fmt.Errorf("unsupported provider type: %s", providerType)
120+
}
121+
}
122+
110123
func GetControllerName() string {
111124
return ControllerConfig.ControllerName
112125
}

internal/controller/config/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import (
1616
"github.com/apache/apisix-ingress-controller/internal/types"
1717
)
1818

19+
type ProviderType string
20+
21+
const (
22+
ProviderTypeStandalone ProviderType = "apisix-standalone"
23+
ProviderTypeAPI7EE ProviderType = "api7ee"
24+
)
25+
1926
const (
2027
// IngressAPISIXLeader is the default election id for the controller
2128
// leader election.
@@ -68,6 +75,7 @@ type LeaderElection struct {
6875
}
6976

7077
type ProviderConfig struct {
78+
Type ProviderType `json:"type" yaml:"type"`
7179
SyncPeriod types.TimeDuration `json:"sync_period" yaml:"sync_period"`
7280
InitSyncDelay types.TimeDuration `json:"init_sync_delay" yaml:"init_sync_delay"`
7381
}

internal/controller/gateway_controller.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
169169
}
170170
}
171171

172-
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
173-
acceptStatus = conditionStatus{
174-
status: false,
175-
msg: err.Error(),
176-
}
177-
}
178-
179172
listenerStatuses, err := getListenerStatus(ctx, r.Client, gateway)
180173
if err != nil {
181174
r.Log.Error(err, "failed to get listener status", "gateway", req.NamespacedName)
@@ -194,21 +187,26 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
194187

195188
r.Updater.Update(status.Update{
196189
NamespacedName: NamespacedName(gateway),
197-
Resource: gateway.DeepCopy(),
190+
Resource: &gatewayv1.Gateway{},
198191
Mutator: status.MutatorFunc(func(obj client.Object) client.Object {
199192
t, ok := obj.(*gatewayv1.Gateway)
200193
if !ok {
201194
err := fmt.Errorf("unsupported object type %T", obj)
202195
panic(err)
203196
}
204-
t.Status = gateway.Status
205-
return t
197+
tCopy := t.DeepCopy()
198+
tCopy.Status = gateway.Status
199+
return tCopy
206200
}),
207201
})
208202

209203
return ctrl.Result{}, nil
210204
}
211205

206+
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
207+
return ctrl.Result{}, fmt.Errorf("failed to update gateway %s: %w", req.NamespacedName, err)
208+
}
209+
212210
return ctrl.Result{}, nil
213211
}
214212

0 commit comments

Comments
 (0)