Skip to content

Commit

Permalink
Update higress ingress annotation (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpecialYang committed Nov 10, 2022
1 parent 268c733 commit da93352
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 1,427 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
external
out
*.out
*.tgz
*.wasm
.idea/
Expand Down
37 changes: 15 additions & 22 deletions pkg/ingress/config/ingress_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
AnnotationsConfig: &annotations.Ingress{
DownstreamTLS: &annotations.DownstreamTLSConfig{
TlsMinVersion: annotations.TLSProtocolVersion("TLSv1.1"),
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
},
},
},
Expand Down Expand Up @@ -249,8 +248,7 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
AnnotationsConfig: &annotations.Ingress{
DownstreamTLS: &annotations.DownstreamTLSConfig{
TlsMinVersion: annotations.TLSProtocolVersion("TLSv1.2"),
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
},
},
},
Expand Down Expand Up @@ -284,10 +282,9 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
Hosts: []string{"foo.com"},
Tls: &networking.ServerTLSSettings{
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1beta1__/wakanda/foo-com",
MinProtocolVersion: networking.ServerTLSSettings_TLSV1_1,
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1beta1__/wakanda/foo-com",
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
},
},
},
Expand Down Expand Up @@ -321,10 +318,9 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
Hosts: []string{"test.com"},
Tls: &networking.ServerTLSSettings{
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1beta1__/wakanda/test-com",
MinProtocolVersion: networking.ServerTLSSettings_TLSV1_1,
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1beta1__/wakanda/test-com",
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256", "AES256-SHA"},
},
},
},
Expand Down Expand Up @@ -466,8 +462,7 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
AnnotationsConfig: &annotations.Ingress{
DownstreamTLS: &annotations.DownstreamTLSConfig{
TlsMinVersion: annotations.TLSProtocolVersion("TLSv1.2"),
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
},
},
},
Expand Down Expand Up @@ -501,10 +496,9 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
Hosts: []string{"foo.com"},
Tls: &networking.ServerTLSSettings{
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1__/wakanda/foo-com",
MinProtocolVersion: networking.ServerTLSSettings_TLSV1_2,
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1__/wakanda/foo-com",
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
},
},
},
Expand Down Expand Up @@ -538,10 +532,9 @@ func TestConvertGatewaysForIngress(t *testing.T) {
},
Hosts: []string{"test.com"},
Tls: &networking.ServerTLSSettings{
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1__/wakanda/test-com",
MinProtocolVersion: networking.ServerTLSSettings_TLSV1_2,
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
Mode: networking.ServerTLSSettings_SIMPLE,
CredentialName: "kubernetes-ingress://ingress-v1__/wakanda/test-com",
CipherSuites: []string{"ECDHE-RSA-AES128-GCM-SHA256"},
},
},
},
Expand Down
28 changes: 0 additions & 28 deletions pkg/ingress/kube/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ type Ingress struct {

IPAccessControl *IPAccessControlConfig

HeaderControl *HeaderControlConfig

Timeout *TimeoutConfig

Retry *RetryConfig

LoadBalance *LoadBalanceConfig

localRateLimit *localRateLimitConfig

Fallback *FallbackConfig

Auth *AuthConfig
Expand Down Expand Up @@ -105,22 +99,6 @@ func (i *Ingress) NeedTrafficPolicy() bool {
i.LoadBalance != nil
}

func (i *Ingress) MergeHostIPAccessControlIfNotExist(ac *IPAccessControlConfig) {
if i.IPAccessControl != nil && i.IPAccessControl.Domain != nil {
return
}

if ac != nil && ac.Domain != nil {
if i.IPAccessControl == nil {
i.IPAccessControl = &IPAccessControlConfig{
Domain: ac.Domain,
}
} else {
i.IPAccessControl.Domain = ac.Domain
}
}
}

type AnnotationHandler interface {
Parser
GatewayHandler
Expand All @@ -147,11 +125,8 @@ func NewAnnotationHandlerManager() AnnotationHandler {
rewrite{},
upstreamTLS{},
ipAccessControl{},
headerControl{},
timeout{},
retry{},
loadBalance{},
localRateLimit{},
fallback{},
auth{},
},
Expand All @@ -166,10 +141,7 @@ func NewAnnotationHandlerManager() AnnotationHandler {
redirect{},
rewrite{},
ipAccessControl{},
headerControl{},
timeout{},
retry{},
localRateLimit{},
fallback{},
},
trafficPolicyHandlers: []TrafficPolicyHandler{
Expand Down
8 changes: 4 additions & 4 deletions pkg/ingress/kube/annotations/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func TestAuthParse(t *testing.T) {
},
{
input: map[string]string{
buildNginxAnnotationKey(authType): defaultAuthType,
buildMSEAnnotationKey(authSecretAnn): "foo/bar",
buildNginxAnnotationKey(authType): defaultAuthType,
buildHigressAnnotationKey(authSecretAnn): "foo/bar",
},
secret: &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -96,7 +96,7 @@ func TestAuthParse(t *testing.T) {
{
input: map[string]string{
buildNginxAnnotationKey(authType): defaultAuthType,
buildMSEAnnotationKey(authSecretAnn): "foo/bar",
buildHigressAnnotationKey(authSecretAnn): "foo/bar",
buildNginxAnnotationKey(authSecretTypeAnn): string(authMapAuthSecretType),
},
secret: &v1.Secret{
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestAuthParse(t *testing.T) {
{
input: map[string]string{
buildNginxAnnotationKey(authType): defaultAuthType,
buildMSEAnnotationKey(authSecretAnn): "bar",
buildHigressAnnotationKey(authSecretAnn): "bar",
buildNginxAnnotationKey(authSecretTypeAnn): string(authFileAuthSecretType),
},
secret: &v1.Secret{
Expand Down
6 changes: 0 additions & 6 deletions pkg/ingress/kube/annotations/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ func ApplyByWeight(canary, route *networking.HTTPRoute, canaryIngress *Ingress)
// We will process total weight in the end.
route.Route = append(route.Route, canary.Route[0])

// canary route use the header control applied on itself.
headerControl{}.ApplyRoute(canary, canaryIngress)
// Move route level to destination level
canary.Route[0].Headers = canary.Headers

Expand Down Expand Up @@ -168,10 +166,6 @@ func ApplyByHeader(canary, route *networking.HTTPRoute, canaryIngress *Ingress)
}
}

canary.Headers = nil
// canary route use the header control applied on itself.
headerControl{}.ApplyRoute(canary, canaryIngress)

// First add normal route cluster
canary.Route[0].FallbackClusters = append(canary.Route[0].FallbackClusters,
route.Route[0].Destination.DeepCopy())
Expand Down
86 changes: 0 additions & 86 deletions pkg/ingress/kube/annotations/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,89 +166,3 @@ func TestApplyWeight(t *testing.T) {
t.Fatal("Should be equal")
}
}

func TestApplyHeader(t *testing.T) {
route := &networking.HTTPRoute{
Headers: &networking.Headers{
Request: &networking.Headers_HeaderOperations{
Add: map[string]string{
"normal": "true",
},
},
},
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "normal",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
}

canary := &networking.HTTPRoute{
Headers: &networking.Headers{
Request: &networking.Headers_HeaderOperations{
Add: map[string]string{
"canary": "true",
},
},
},
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "canary",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
}

ApplyByHeader(canary, route, &Ingress{
Canary: &CanaryConfig{},
HeaderControl: &HeaderControlConfig{
Request: &HeaderOperation{
Add: map[string]string{
"canary": "true",
},
},
},
})

expect := &networking.HTTPRoute{
Headers: &networking.Headers{
Request: &networking.Headers_HeaderOperations{
Add: map[string]string{
"canary": "true",
},
},
Response: &networking.Headers_HeaderOperations{},
},
Route: []*networking.HTTPRouteDestination{
{
Destination: &networking.Destination{
Host: "canary",
Port: &networking.PortSelector{
Number: 80,
},
},
FallbackClusters: []*networking.Destination{
{
Host: "normal",
Port: &networking.PortSelector{
Number: 80,
},
},
},
},
},
}

if !reflect.DeepEqual(canary, expect) {
t.Fatal("Should be equal")
}
}
4 changes: 2 additions & 2 deletions pkg/ingress/kube/annotations/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func TestCorsParse(t *testing.T) {
},
{
input: Annotations{
buildMSEAnnotationKey(enableCors): "true",
buildHigressAnnotationKey(enableCors): "true",
buildNginxAnnotationKey(allowOrigin): "https://origin-site.com:4443, http://origin-site.com, https://example.org:1199",
buildMSEAnnotationKey(allowMethods): "GET, PUT",
buildHigressAnnotationKey(allowMethods): "GET, PUT",
buildNginxAnnotationKey(allowHeaders): "foo,bar",
buildNginxAnnotationKey(allowCredentials): "false",
buildNginxAnnotationKey(maxAge): "100",
Expand Down
12 changes: 6 additions & 6 deletions pkg/ingress/kube/annotations/default_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestFallbackParse(t *testing.T) {
},
{
input: map[string]string{
buildMSEAnnotationKey(annDefaultBackend): "app",
buildHigressAnnotationKey(annDefaultBackend): "app",
},
expect: &FallbackConfig{
DefaultBackend: model.NamespacedName{
Expand All @@ -85,13 +85,13 @@ func TestFallbackParse(t *testing.T) {
},
{
input: map[string]string{
buildMSEAnnotationKey(annDefaultBackend): "foo/app",
buildHigressAnnotationKey(annDefaultBackend): "foo/app",
},
},
{
input: map[string]string{
buildMSEAnnotationKey(annDefaultBackend): "test/app",
buildNginxAnnotationKey(customHTTPError): "404,503",
buildHigressAnnotationKey(annDefaultBackend): "test/app",
buildNginxAnnotationKey(customHTTPError): "404,503",
},
expect: &FallbackConfig{
DefaultBackend: model.NamespacedName{
Expand All @@ -104,8 +104,8 @@ func TestFallbackParse(t *testing.T) {
},
{
input: map[string]string{
buildMSEAnnotationKey(annDefaultBackend): "test/app",
buildNginxAnnotationKey(customHTTPError): "404,5ac",
buildHigressAnnotationKey(annDefaultBackend): "test/app",
buildNginxAnnotationKey(customHTTPError): "404,5ac",
},
expect: &FallbackConfig{
DefaultBackend: model.NamespacedName{
Expand Down

0 comments on commit da93352

Please sign in to comment.