Skip to content

Commit

Permalink
feat: add v2beta3 (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxthrj authored Dec 6, 2021
1 parent 26d5c5c commit 1bbadf0
Show file tree
Hide file tree
Showing 133 changed files with 3,280 additions and 1,990 deletions.
2 changes: 1 addition & 1 deletion cmd/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ For example, no available LB exists in the bare metal environment.`)
cmd.PersistentFlags().StringVar(&cfg.Kubernetes.IngressClass, "ingress-class", config.IngressClass, "the class of an Ingress object is set using the field IngressClassName in Kubernetes clusters version v1.18.0 or higher or the annotation \"kubernetes.io/ingress.class\" (deprecated)")
cmd.PersistentFlags().StringVar(&cfg.Kubernetes.ElectionID, "election-id", config.IngressAPISIXLeader, "election id used for campaign the controller leader")
cmd.PersistentFlags().StringVar(&cfg.Kubernetes.IngressVersion, "ingress-version", config.IngressNetworkingV1, "the supported ingress api group version, can be \"networking/v1beta1\", \"networking/v1\" (for Kubernetes version v1.19.0 or higher) and \"extensions/v1beta1\"")
cmd.PersistentFlags().StringVar(&cfg.Kubernetes.ApisixRouteVersion, "apisix-route-version", config.ApisixRouteV2alpha1, "the supported apisixroute api group version, can be \"apisix.apache.org/v1\" or \"apisix.apache.org/v2alpha1\"")
cmd.PersistentFlags().StringVar(&cfg.Kubernetes.ApisixRouteVersion, "apisix-route-version", config.ApisixRouteV2beta3, "the supported apisixroute api group version, can be \"apisix.apache.org/v2beta1\" or \"apisix.apache.org/v2beta2\" or \"apisix.apache.org/v2beta3\"")
cmd.PersistentFlags().BoolVar(&cfg.Kubernetes.WatchEndpointSlices, "watch-endpointslices", false, "whether to watch endpointslices rather than endpoints")
cmd.PersistentFlags().StringVar(&cfg.APISIX.BaseURL, "apisix-base-url", "", "the base URL for APISIX admin api / manager api (deprecated, using --default-apisix-cluster-base-url instead)")
cmd.PersistentFlags().StringVar(&cfg.APISIX.AdminKey, "apisix-admin-key", "", "admin key used for the authorization of APISIX admin api / manager api (deprecated, using --default-apisix-cluster-admin-key instead)")
Expand Down
4 changes: 2 additions & 2 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ kubernetes:
# "extensions/v1beta1", default is "networking/v1".
watch_endpointslices: false # whether to watch EndpointSlices rather than Endpoints.

apisix_route_version: "apisix.apache.org/v2beta2" # the supported apisixroute api group version.
# the latest version is "apisix.apache.org/v2beta2".
apisix_route_version: "apisix.apache.org/v2beta3" # the supported apisixroute api group version.
# the latest version is "apisix.apache.org/v2beta3".
# APISIX related configurations.
apisix:
base_url: "http://127.0.0.1:9080/apisix/admin" # (Deprecated, use default_cluster_base_url) the APISIX admin api / manager api
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/practices/proxy-grpc-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ If you don't see a command prompt, try pressing enter.
```bash
kubectl apply -f - <<EOF
apiVersion: apisix.apache.org/v2beta2
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
name: grpc-proxy-route
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/practices/the-hard-way.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ data:
- "apisix.ingress=watching"
ingress_class: "apisix"
ingress_version: "networking/v1"
apisix_route_version: "apisix.apache.org/v2beta1"
apisix_route_version: "apisix.apache.org/v2beta3"
apisix:
default_cluster_base_url: "http://apisix-admin.apisix:9180/apisix/admin"
default_cluster_admin_key: "edd1c9f034335f136f87ad84b625c8f1"
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ you can use the [`conftest`](https://github.com/open-policy-agent/conftest) tool
Here's a quick example.

```yaml
apiVersion: apisix.apache.org/v2beta2
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
name: httpbin-route
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/apisix_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
)

Expand All @@ -46,9 +46,9 @@ var ApisixConsumerValidator = kwhvalidating.ValidatorFunc(
switch ac := object.(type) {
case *v2beta1.ApisixRoute:
spec = ac.Spec
case *v2alpha1.ApisixRoute:
case *v2beta2.ApisixRoute:
spec = ac.Spec
case *v1.ApisixRoute:
case *v2beta3.ApisixRoute:
spec = ac.Spec
default:
return &kwhvalidating.ValidatorResult{Valid: false, Message: errNotApisixConsumer.Error()}, errNotApisixConsumer
Expand Down
19 changes: 2 additions & 17 deletions pkg/api/validation/apisix_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
)

Expand Down Expand Up @@ -80,7 +79,7 @@ var ApisixRouteValidator = kwhvalidating.ValidatorFunc(
}
}
}
case *v2alpha1.ApisixRoute:
case *v2beta3.ApisixRoute:
spec = ar.Spec

for _, h := range ar.Spec.HTTP {
Expand All @@ -92,20 +91,6 @@ var ApisixRouteValidator = kwhvalidating.ValidatorFunc(
}
}
}
case *v1.ApisixRoute:
spec = ar.Spec

for _, r := range ar.Spec.Rules {
for _, path := range r.Http.Paths {
for _, p := range path.Plugins {
if p.Enable {
plugins = append(plugins, apisixRoutePlugin{
p.Name, p.Config,
})
}
}
}
}
default:
return &kwhvalidating.ValidatorResult{Valid: false, Message: errNotApisixRoute.Error()}, errNotApisixRoute
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/apisix_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"testing"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
api "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
)

Expand Down Expand Up @@ -125,12 +125,12 @@ func Test_validatePlugin(t *testing.T) {
t.Errorf("validatePlugin() gotValid = %v, want %v", gotValid, tt.wantValid)
}

gotValid, _ = validatePlugin(fakeClient, tt.pluginName, v2alpha1.ApisixRouteHTTPPluginConfig(tt.pluginConfig))
gotValid, _ = validatePlugin(fakeClient, tt.pluginName, v2beta3.ApisixRouteHTTPPluginConfig(tt.pluginConfig))
if gotValid != tt.wantValid {
t.Errorf("validatePlugin() gotValid = %v, want %v", gotValid, tt.wantValid)
}

gotValid, _ = validatePlugin(fakeClient, tt.pluginName, v1.Config(tt.pluginConfig))
gotValid, _ = validatePlugin(fakeClient, tt.pluginName, v2beta2.ApisixRouteHTTPPluginConfig(tt.pluginConfig))
if gotValid != tt.wantValid {
t.Errorf("validatePlugin() gotValid = %v, want %v", gotValid, tt.wantValid)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/apisix_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
)

Expand All @@ -46,9 +46,9 @@ var ApisixTlsValidator = kwhvalidating.ValidatorFunc(
switch at := object.(type) {
case *v2beta1.ApisixRoute:
spec = at.Spec
case *v2alpha1.ApisixRoute:
case *v2beta2.ApisixRoute:
spec = at.Spec
case *v1.ApisixRoute:
case *v2beta3.ApisixRoute:
spec = at.Spec
default:
return &kwhvalidating.ValidatorResult{Valid: false, Message: errNotApisixTls.Error()}, errNotApisixTls
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/validation/apisix_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
v1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta1"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta2"
"github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
)

Expand All @@ -46,9 +46,9 @@ var ApisixUpstreamValidator = kwhvalidating.ValidatorFunc(
switch au := object.(type) {
case *v2beta1.ApisixRoute:
spec = au.Spec
case *v2alpha1.ApisixRoute:
case *v2beta2.ApisixRoute:
spec = au.Spec
case *v1.ApisixRoute:
case *v2beta3.ApisixRoute:
spec = au.Spec
default:
return &kwhvalidating.ValidatorResult{Valid: false, Message: errNotApisixUpstream.Error()}, errNotApisixUpstream
Expand Down
4 changes: 2 additions & 2 deletions pkg/apisix/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"strings"
"testing"

"github.com/apache/apisix-ingress-controller/pkg/metrics"
"github.com/stretchr/testify/assert"

"golang.org/x/net/nettest"

"github.com/apache/apisix-ingress-controller/pkg/metrics"
)

type fakeAPISIXPluginSrv struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apisix/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"strings"
"testing"

"github.com/apache/apisix-ingress-controller/pkg/metrics"
"github.com/stretchr/testify/assert"
"golang.org/x/net/nettest"

"github.com/apache/apisix-ingress-controller/pkg/metrics"
)

type fakeAPISIXSchemaSrv struct {
Expand Down
8 changes: 3 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ const (
// WARNING: ingress.extensions/v1beta1 is deprecated in v1.14+, and will be unavilable
// in v1.22.
IngressExtensionsV1beta1 = "extensions/v1beta1"
// ApisixRouteV1 represents apisixroute.apisix.apache.org/v1
ApisixRouteV1 = "apisix.apache.org/v1"
// ApisixRouteV2alpha1 represents apisixroute.apisix.apache.org/v2alpha1
ApisixRouteV2alpha1 = "apisix.apache.org/v2alpha1"
// ApisixRouteV2beta1 represents apisixroute.apisix.apache.org/v2beta1
ApisixRouteV2beta1 = "apisix.apache.org/v2beta1"
// ApisixRouteV2beta2 represents apisixroute.apisix.apache.org/v2beta2
ApisixRouteV2beta2 = "apisix.apache.org/v2beta2"
// ApisixRouteV2beta3 represents apisixroute.apisix.apache.org/v2beta3
ApisixRouteV2beta3 = "apisix.apache.org/v2beta3"

_minimalResyncInterval = 30 * time.Second
)
Expand Down Expand Up @@ -131,7 +129,7 @@ func NewDefaultConfig() *Config {
ElectionID: IngressAPISIXLeader,
IngressClass: IngressClass,
IngressVersion: IngressNetworkingV1,
ApisixRouteVersion: ApisixRouteV2alpha1,
ApisixRouteVersion: ApisixRouteV2beta3,
WatchEndpointSlices: false,
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestNewConfigFromFile(t *testing.T) {
ElectionID: "my-election-id",
IngressClass: IngressClass,
IngressVersion: IngressNetworkingV1,
ApisixRouteVersion: ApisixRouteV2alpha1,
ApisixRouteVersion: ApisixRouteV2beta3,
},
APISIX: APISIXConfig{
DefaultClusterName: "default",
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestConfigWithEnvVar(t *testing.T) {
ElectionID: "my-election-id",
IngressClass: IngressClass,
IngressVersion: IngressNetworkingV1,
ApisixRouteVersion: ApisixRouteV2alpha1,
ApisixRouteVersion: ApisixRouteV2beta3,
},
APISIX: APISIXConfig{
DefaultClusterName: "default",
Expand Down
12 changes: 6 additions & 6 deletions pkg/ingress/apisix_cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/apache/apisix-ingress-controller/pkg/apisix"
configv2alpha1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
configv2beta3 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
"github.com/apache/apisix-ingress-controller/pkg/types"
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *apisixClusterConfigController) sync(ctx context.Context, ev *types.Even
log.Warnf("discard the stale ApisixClusterConfig delete event since the %s exists", key)
return nil
}
acc = ev.Tombstone.(*configv2alpha1.ApisixClusterConfig)
acc = ev.Tombstone.(*configv2beta3.ApisixClusterConfig)
}

// Currently we don't handle multiple cluster, so only process
Expand Down Expand Up @@ -219,8 +219,8 @@ func (c *apisixClusterConfigController) onAdd(obj interface{}) {
}

func (c *apisixClusterConfigController) onUpdate(oldObj, newObj interface{}) {
prev := oldObj.(*configv2alpha1.ApisixClusterConfig)
curr := newObj.(*configv2alpha1.ApisixClusterConfig)
prev := oldObj.(*configv2beta3.ApisixClusterConfig)
curr := newObj.(*configv2beta3.ApisixClusterConfig)
if prev.ResourceVersion >= curr.ResourceVersion {
return
}
Expand All @@ -243,13 +243,13 @@ func (c *apisixClusterConfigController) onUpdate(oldObj, newObj interface{}) {
}

func (c *apisixClusterConfigController) onDelete(obj interface{}) {
acc, ok := obj.(*configv2alpha1.ApisixClusterConfig)
acc, ok := obj.(*configv2beta3.ApisixClusterConfig)
if !ok {
tombstone, ok := obj.(*cache.DeletedFinalStateUnknown)
if !ok {
return
}
acc = tombstone.Obj.(*configv2alpha1.ApisixClusterConfig)
acc = tombstone.Obj.(*configv2beta3.ApisixClusterConfig)
}

key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
Expand Down
12 changes: 6 additions & 6 deletions pkg/ingress/apisix_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"

configv2alpha1 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2alpha1"
configv2beta3 "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
"github.com/apache/apisix-ingress-controller/pkg/log"
"github.com/apache/apisix-ingress-controller/pkg/types"
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *apisixConsumerController) sync(ctx context.Context, ev *types.Event) er
log.Warnf("discard the stale ApisixConsumer delete event since the %s exists", key)
return nil
}
ac = ev.Tombstone.(*configv2alpha1.ApisixConsumer)
ac = ev.Tombstone.(*configv2beta3.ApisixConsumer)
}

consumer, err := c.controller.translator.TranslateApisixConsumer(ac)
Expand Down Expand Up @@ -174,8 +174,8 @@ func (c *apisixConsumerController) onAdd(obj interface{}) {
}

func (c *apisixConsumerController) onUpdate(oldObj, newObj interface{}) {
prev := oldObj.(*configv2alpha1.ApisixConsumer)
curr := newObj.(*configv2alpha1.ApisixConsumer)
prev := oldObj.(*configv2beta3.ApisixConsumer)
curr := newObj.(*configv2beta3.ApisixConsumer)
if prev.ResourceVersion >= curr.ResourceVersion {
return
}
Expand All @@ -201,13 +201,13 @@ func (c *apisixConsumerController) onUpdate(oldObj, newObj interface{}) {
}

func (c *apisixConsumerController) onDelete(obj interface{}) {
ac, ok := obj.(*configv2alpha1.ApisixConsumer)
ac, ok := obj.(*configv2beta3.ApisixConsumer)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
return
}
ac = tombstone.Obj.(*configv2alpha1.ApisixConsumer)
ac = tombstone.Obj.(*configv2beta3.ApisixConsumer)
}

key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
Expand Down
Loading

0 comments on commit 1bbadf0

Please sign in to comment.