Skip to content

Commit

Permalink
Merge pull request #1219 from ishankhare07/action-config-alb
Browse files Browse the repository at this point in the history
add redirectconfig to alb ingress annotation
  • Loading branch information
FabianKramm authored Sep 21, 2023
2 parents fff3cf4 + c1172ca commit f23fac2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
23 changes: 13 additions & 10 deletions pkg/controllers/resources/ingresses/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ func TestSync(t *testing.T) {
Namespace: baseIngress.Namespace,
Labels: baseIngress.Labels,
Annotations: map[string]string{
"nginx.ingress.kubernetes.io/auth-secret": "my-secret",
"alb.ingress.kubernetes.io/actions.testservice": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service\",\"servicePort\":\"80\",\"weight\":100}]}}",
"nginx.ingress.kubernetes.io/auth-secret": "my-secret",
"alb.ingress.kubernetes.io/actions.testservice": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service\",\"servicePort\":\"80\",\"weight\":100}]}}",
"alb.ingress.kubernetes.io/actions.ssl-redirect": `{"type": "redirect", "redirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}`,
},
},
},
Expand All @@ -390,8 +391,9 @@ func TestSync(t *testing.T) {
Namespace: baseIngress.Namespace,
Labels: baseIngress.Labels,
Annotations: map[string]string{
"alb.ingress.kubernetes.io/actions.testservice": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service\",\"servicePort\":\"80\",\"weight\":100}]}}",
"nginx.ingress.kubernetes.io/auth-secret": "my-secret",
"alb.ingress.kubernetes.io/actions.testservice": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service\",\"servicePort\":\"80\",\"weight\":100}]}}",
"alb.ingress.kubernetes.io/actions.ssl-redirect": `{"type": "redirect", "redirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}`,
"nginx.ingress.kubernetes.io/auth-secret": "my-secret",
},
},
},
Expand All @@ -405,12 +407,13 @@ func TestSync(t *testing.T) {
Namespace: createdIngress.Namespace,
Labels: createdIngress.Labels,
Annotations: map[string]string{
"vcluster.loft.sh/managed-annotations": "alb.ingress.kubernetes.io/actions.testservice-x-test-x-suffix\nnginx.ingress.kubernetes.io/auth-secret",
"nginx.ingress.kubernetes.io/auth-secret": translate.Default.PhysicalName("my-secret", baseIngress.Namespace),
"vcluster.loft.sh/object-name": baseIngress.Name,
"vcluster.loft.sh/object-namespace": baseIngress.Namespace,
translate.UIDAnnotation: "",
"alb.ingress.kubernetes.io/actions.testservice-x-test-x-suffix": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service-x-test-x-suffix\",\"servicePort\":\"80\",\"weight\":100}]}}",
"vcluster.loft.sh/managed-annotations": "alb.ingress.kubernetes.io/actions.ssl-redirect-x-test-x-suffix\nalb.ingress.kubernetes.io/actions.testservice-x-test-x-suffix\nnginx.ingress.kubernetes.io/auth-secret",
"nginx.ingress.kubernetes.io/auth-secret": translate.Default.PhysicalName("my-secret", baseIngress.Namespace),
"vcluster.loft.sh/object-name": baseIngress.Name,
"vcluster.loft.sh/object-namespace": baseIngress.Namespace,
translate.UIDAnnotation: "",
"alb.ingress.kubernetes.io/actions.testservice-x-test-x-suffix": "{\"forwardConfig\":{\"targetGroups\":[{\"serviceName\":\"nginx-service-x-test-x-suffix\",\"servicePort\":\"80\",\"weight\":100}]}}",
"alb.ingress.kubernetes.io/actions.ssl-redirect-x-test-x-suffix": `{"type":"redirect","forwardConfig":{},"redirectConfig":{"Port":"443","Protocol":"HTTPS","StatusCode":"HTTP_301"}}`,
},
},
},
Expand Down
17 changes: 10 additions & 7 deletions pkg/controllers/resources/ingresses/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ func getActionOrConditionValue(annotation, actionOrCondition string) string {
return ""
}

// ref https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/pkg/ingress/config_types.go
type actionPayload struct {
Type string `json:"type,omitempty"`
ForwardConfig struct {
TargetGroups []map[string]interface{} `json:"targetGroups,omitempty"`
TargetGroupStickinessConfig map[string]interface{} `json:"targetGroupStickinessConfig,omitempty"`
} `json:"forwardConfig,omitempty"`
RedirectConfig map[string]interface{} `json:"redirectConfig,omitempty"`
}

func ProcessAlbAnnotations(namespace string, k string, v string) (string, string) {
if strings.HasPrefix(k, AlbActionsAnnotation) {
type actionPayload struct {
Type string `json:"type,omitempty"`
ForwardConfig struct {
TargetGroups []map[string]interface{} `json:"targetGroups,omitempty"`
TargetGroupStickinessConfig map[string]interface{} `json:"targetGroupStickinessConfig,omitempty"`
} `json:"forwardConfig,omitempty"`
}
// change k
action := getActionOrConditionValue(k, ActionsSuffix)
if !strings.Contains(k, "x-"+namespace+"-x") {
Expand Down

0 comments on commit f23fac2

Please sign in to comment.