Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
template: |
addresses:
- type: Hostname
value: {{ .Resources.LB.status.atProvider.dnsName }}
value: {{ (index .Resources.LB 0).status.atProvider.dnsName }}
resourceTemplates:
childGateway: |
apiVersion: gateway.networking.k8s.io/v1beta1
Expand Down Expand Up @@ -153,7 +153,7 @@ spec:
{{- toYaml .Values.tags | nindent 4 }}
{{ end }}
spec:
targetGroupARN: {{ .Resources.LBTargetGroup.status.atProvider.arn }}
targetGroupARN: {{ (index .Resources.LBTargetGroup 0).status.atProvider.arn }}
targetType: ip
serviceRef:
name: {{ .Gateway.metadata.name }}-child
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
status:
template: |
addresses:
{{ range .Resources.loadBalancer.status.loadBalancer.ingress }}
{{ range (index .Resources.loadBalancer 0).status.loadBalancer.ingress }}
- type: IPAddress
value: {{ .ip }}
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion controllers/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ spec:
name: default
`

var _ = Describe("Common functions", func() {
var _ = Describe("Attached policies and value precedence", func() {

const (
timeout = time.Second * 10
Expand Down
6 changes: 3 additions & 3 deletions controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if tmpl, errs := parseSingleTemplate("status", tmplStr); errs != nil {
logger.Info("unable to parse status template", "temporary error", errs)
} else {
if statusMap, errs := template2map(tmpl, &templateValues); errs != nil {
if statusMap, errs := template2maps(tmpl, &templateValues); errs != nil {
logger.Info("unable to render status template", "temporary error", errs, "template", tmplStr, "values", templateValues)
} else {
gw.Status.Addresses = []gatewayapi.GatewayAddress{}
_, found := statusMap["addresses"]
_, found := statusMap[0]["addresses"] // FIXME, more addresses?
if found {
addresses := statusMap["addresses"]
addresses := statusMap[0]["addresses"]
if errs := mapstructure.Decode(addresses, &gw.Status.Addresses); errs != nil {
// This is probably not a temporary error
logger.Error(errs, "unable to decode status data")
Expand Down
29 changes: 24 additions & 5 deletions controllers/gateway_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ kind: GatewayClassBlueprint
metadata:
name: default-gateway-class
spec:
values:
default:
configmap2SuffixData:
- one
- two
- three
gatewayTemplate:
status:
template: |
addresses:
{{ toYaml .Resources.childGateway.status.addresses | nindent 2}}
{{ toYaml (index .Resources.childGateway 0).status.addresses | nindent 2}}
resourceTemplates:
childGateway: |
apiVersion: gateway.networking.k8s.io/v1beta1
Expand All @@ -109,14 +115,25 @@ spec:
data:
valueToRead1: Hello
valueToRead2: World
configMapTestIntermediate: |
configMapTestIntermediate1: |
apiVersion: v1
kind: ConfigMap
metadata:
name: intermediate-configmap
name: intermediate1-configmap
namespace: {{ .Gateway.metadata.namespace }}
data:
valueIntermediate: {{ .Resources.configMapTestSource.data.valueToRead1 }}
valueIntermediate: {{ (index .Resources.configMapTestSource 0).data.valueToRead1 }}
configMapTestIntermediate2: |
{{ range $idx,$suffix := .Values.configmap2SuffixData }}
apiVersion: v1
kind: ConfigMap
metadata:
name: intermediate2-configmap-{{ $idx }}
namespace: {{ $.Gateway.metadata.namespace }}
data:
valueIntermediate: {{ (index $.Resources.configMapTestSource 0).data.valueToRead1 }}-{{ $suffix }}
---
{{ end }}
# Use references to multiple resources coupled with template pipeline and functions
configMapTestDestination: |
apiVersion: v1
Expand All @@ -125,7 +142,8 @@ spec:
name: dst-configmap
namespace: {{ .Gateway.metadata.namespace }}
data:
valueRead: {{ printf "%s, %s" .Resources.configMapTestIntermediate.data.valueIntermediate .Resources.configMapTestSource.data.valueToRead2 | upper }}
valueRead: {{ printf "%s, %s" (index .Resources.configMapTestIntermediate1 0).data.valueIntermediate (index .Resources.configMapTestSource 0).data.valueToRead2 | upper }}
valueRead2: {{ printf "Testing, one two %s" (index .Resources.configMapTestIntermediate2 2).data.valueIntermediate | upper }}
httpRouteTemplate:
resourceTemplates:
shadowHttproute: |
Expand Down Expand Up @@ -270,6 +288,7 @@ var _ = Describe("Gateway controller", func() {

By("Setting the content of the destination configmap")
Expect(cm.Data["valueRead"]).To(Equal("HELLO, WORLD"))
Expect(cm.Data["valueRead2"]).To(Equal("TESTING, ONE TWO HELLO-THREE"))
})
})
})
Expand Down
36 changes: 21 additions & 15 deletions controllers/statuscheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,40 @@ limitations under the License.
package controllers

import (
"fmt"

"sigs.k8s.io/cli-utils/pkg/kstatus/status"
)

// Given a slice of template states, compute the overall
// health/readiness status. The general approach is to test for a
// `Ready` status condition, which is implemented through kstatus.
func statusIsReady(templates []*TemplateResource) (bool, error) {
for _, tmplRes := range templates {
if tmplRes.Current == nil {
return false, nil
}
res, err := status.Compute(tmplRes.Current)
if err != nil {
return false, err
}
if res.Status != status.CurrentStatus {
return false, nil
func statusIsReady(templates []*ResourceTemplateState) (bool, error) {
for _, tmpl := range templates {
for _, res := range tmpl.NewResources {
if res.Current == nil {
return false, nil
}
res, err := status.Compute(res.Current)
if err != nil {
return false, err
}
if res.Status != status.CurrentStatus {
return false, nil
}
}
}
return true, nil
}

// Build a list of template names which are not yet reconciled. Useful for status reporting
func statusExistingTemplates(templates []*TemplateResource) []string {
func statusExistingTemplates(templates []*ResourceTemplateState) []string {
var missing []string
for _, tmplRes := range templates {
if tmplRes.Current == nil {
missing = append(missing, tmplRes.TemplateName)
for _, tmpl := range templates {
for resIdx, res := range tmpl.NewResources {
if res.Current == nil {
missing = append(missing, fmt.Sprintf("%s[%d]", tmpl.TemplateName, resIdx))
}
}
}
return missing
Expand Down
Loading