Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
k8s.io/client-go v0.26.0
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
sigs.k8s.io/controller-runtime v0.14.1
sigs.k8s.io/gateway-api v0.6.0-rc2
sigs.k8s.io/gateway-api v0.6.0
sigs.k8s.io/yaml v1.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.14.1 h1:vThDes9pzg0Y+UbCPY3Wj34CGIYPgdmspPm2GIpxpzM=
sigs.k8s.io/controller-runtime v0.14.1/go.mod h1:GaRkrY8a7UZF0kqFFbUKG7n9ICiTY5T55P1RiE3UZlU=
sigs.k8s.io/gateway-api v0.6.0-rc2 h1:Dqys/rLadwLsujhJZixggxXMTCAkz0byRpyllmJdvXY=
sigs.k8s.io/gateway-api v0.6.0-rc2/go.mod h1:EYJT+jlPWTeNskjV0JTki/03WX1cyAnBhwBJfYHpV/0=
sigs.k8s.io/gateway-api v0.6.0 h1:v2FqrN2ROWZLrSnI2o91taHR8Sj3s+Eh3QU7gLNWIqA=
sigs.k8s.io/gateway-api v0.6.0/go.mod h1:EYJT+jlPWTeNskjV0JTki/03WX1cyAnBhwBJfYHpV/0=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
Expand Down
6 changes: 4 additions & 2 deletions internal/gatewayapi/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (l *ListenerContext) SetCondition(conditionType v1beta1.ListenerConditionTy
// return early if the condition is unchanged
if existing.Status == cond.Status &&
existing.Reason == cond.Reason &&
existing.Message == cond.Message {
existing.Message == cond.Message &&
existing.ObservedGeneration == cond.ObservedGeneration {
return
}
idx = i
Expand Down Expand Up @@ -570,7 +571,8 @@ func (r *RouteParentContext) SetCondition(route RouteContext, conditionType v1be
// return early if the condition is unchanged
if existing.Status == cond.Status &&
existing.Reason == cond.Reason &&
existing.Message == cond.Message {
existing.Message == cond.Message &&
existing.ObservedGeneration == cond.ObservedGeneration {
return
}
idx = i
Expand Down
38 changes: 18 additions & 20 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,33 @@ func (r *gatewayAPIReconciler) getNamespace(ctx context.Context, name string) (*
return ns, nil
}

func (r *gatewayAPIReconciler) statusUpdateForGateway(gtw *gwapiv1b1.Gateway, svc *corev1.Service, deploy *appsv1.Deployment) {
func (r *gatewayAPIReconciler) statusUpdateForGateway(ctx context.Context, gtw *gwapiv1b1.Gateway) {
// nil check for unit tests.
if r.statusUpdater == nil {
return
}

// Get deployment
deploy, err := r.envoyDeploymentForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Deployment for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
}

// Get service
svc, err := r.envoyServiceForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Service for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
}
// update scheduled condition
status.UpdateGatewayStatusScheduledCondition(gtw, true)
// update address field and ready condition
status.UpdateGatewayStatusReadyCondition(gtw, svc, deploy)

key := utils.NamespacedName(gtw)

// publish status
// do it inline since this code flow updates the
// Status.Addresses field whereas the message bus / subscriber
// does not.
r.statusUpdater.Send(status.Update{
NamespacedName: key,
Resource: new(gwapiv1b1.Gateway),
Expand All @@ -301,8 +312,9 @@ func (r *gatewayAPIReconciler) statusUpdateForGateway(gtw *gwapiv1b1.Gateway, sv
panic(fmt.Sprintf("unsupported object type %T", obj))
}
gCopy := g.DeepCopy()
gCopy.Status.Conditions = status.MergeConditions(gCopy.Status.Conditions, gtw.Status.Conditions...)
gCopy.Status.Conditions = gtw.Status.Conditions
gCopy.Status.Addresses = gtw.Status.Addresses
gCopy.Status.Listeners = gtw.Status.Listeners
return gCopy
}),
})
Expand Down Expand Up @@ -839,21 +851,7 @@ func (r *gatewayAPIReconciler) subscribeAndUpdateStatus(ctx context.Context) {
if update.Delete {
return
}
key := update.Key
val := update.Value
r.statusUpdater.Send(status.Update{
NamespacedName: key,
Resource: new(gwapiv1b1.Gateway),
Mutator: status.MutatorFunc(func(obj client.Object) client.Object {
g, ok := obj.(*gwapiv1b1.Gateway)
if !ok {
panic(fmt.Sprintf("unsupported object type %T", obj))
}
gCopy := g.DeepCopy()
gCopy.Status.Listeners = val.Status.Listeners
return gCopy
}),
})
r.statusUpdateForGateway(ctx, update.Value)
},
)
r.log.Info("gateway status subscriber shutting down")
Expand Down
27 changes: 5 additions & 22 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,10 @@ func (r *gatewayAPIReconciler) validateServiceForReconcile(obj client.Object) bo
return false
}

// Check if the Service belongs to a Gateway, if so, find the Gateway. If
// Check if the Service belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, svc.GetLabels())
if gtw != nil {
// Check if the Deployment for the Gateway also exists, if it does, proceed with
// the Gateway status update.
deployment, err := r.envoyDeploymentForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Deployment for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
return false
}

r.statusUpdateForGateway(gtw, svc, deployment)
r.statusUpdateForGateway(ctx, gtw)
return false
}

Expand Down Expand Up @@ -188,19 +179,11 @@ func (r *gatewayAPIReconciler) validateDeploymentForReconcile(obj client.Object)

// Only deployments in the configured namespace should be reconciled.
if deployment.Namespace == r.namespace {
// Check if the deployment belongs to a Gateway, if so, find the Gateway.
// Check if the deployment belongs to a Gateway, if so, update the Gateway status.
gtw := r.findOwningGateway(ctx, deployment.GetLabels())
if gtw != nil {
// Check if the Service for the Gateway also exists, if it does, proceed with
// the Gateway status update.
svc, err := r.envoyServiceForGateway(ctx, gtw)
if err != nil {
r.log.Info("failed to get Service for gateway",
"namespace", gtw.Namespace, "name", gtw.Name)
return false
}

r.statusUpdateForGateway(gtw, svc, deployment)
r.statusUpdateForGateway(ctx, gtw)
return false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/1086
gateway.networking.k8s.io/bundle-version: v0.6.0-rc1
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/1538
gateway.networking.k8s.io/bundle-version: v0.6.0
gateway.networking.k8s.io/channel: experimental
creationTimestamp: null
name: gateways.gateway.networking.k8s.io
Expand All @@ -27,8 +27,8 @@ spec:
- jsonPath: .status.addresses[*].value
name: Address
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
- jsonPath: .status.conditions[?(@.type=="Programmed")].status
name: Programmed
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -492,6 +492,11 @@ spec:
reason: Pending
status: Unknown
type: Accepted
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: "Conditions describe the current conditions of the Gateway.
\n Implementations should prefer to express Gateway conditions using
the `GatewayConditionType` and `GatewayConditionReason` constants
Expand All @@ -502,13 +507,14 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
\n \ttype FooStatus struct{ \t // Represents the observations
of a foo's current state. \t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
\t // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
\t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -588,14 +594,15 @@ spec:
description: "Condition contains details for one aspect of
the current state of this API Resource. --- This struct
is intended for direct use as an array at the field path
.status.conditions. For example, type FooStatus struct{
\ // Represents the observations of a foo's current state.
\ // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map //
+listMapKey=type Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
.status.conditions. For example, \n \ttype FooStatus struct{
\t // Represents the observations of a foo's current
state. \t // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" \t // +patchMergeKey=type
\t // +patchStrategy=merge \t // +listType=map \t
\ // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other
fields \t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -724,8 +731,8 @@ spec:
- jsonPath: .status.addresses[*].value
name: Address
type: string
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
- jsonPath: .status.conditions[?(@.type=="Programmed")].status
name: Programmed
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -1186,6 +1193,11 @@ spec:
reason: Pending
status: Unknown
type: Accepted
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: Waiting for controller
reason: Pending
status: Unknown
type: Programmed
description: "Conditions describe the current conditions of the Gateway.
\n Implementations should prefer to express Gateway conditions using
the `GatewayConditionType` and `GatewayConditionReason` constants
Expand All @@ -1196,13 +1208,14 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
\n \ttype FooStatus struct{ \t // Represents the observations
of a foo's current state. \t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
\t // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
\t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -1282,14 +1295,15 @@ spec:
description: "Condition contains details for one aspect of
the current state of this API Resource. --- This struct
is intended for direct use as an array at the field path
.status.conditions. For example, type FooStatus struct{
\ // Represents the observations of a foo's current state.
\ // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map //
+listMapKey=type Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
.status.conditions. For example, \n \ttype FooStatus struct{
\t // Represents the observations of a foo's current
state. \t // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" \t // +patchMergeKey=type
\t // +patchStrategy=merge \t // +listType=map \t
\ // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other
fields \t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/1086
gateway.networking.k8s.io/bundle-version: v0.6.0-rc1
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/1538
gateway.networking.k8s.io/bundle-version: v0.6.0
gateway.networking.k8s.io/channel: experimental
creationTimestamp: null
name: gatewayclasses.gateway.networking.k8s.io
Expand Down Expand Up @@ -148,13 +148,14 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
\n \ttype FooStatus struct{ \t // Represents the observations
of a foo's current state. \t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
\t // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
\t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -349,13 +350,14 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
\n \ttype FooStatus struct{ \t // Represents the observations
of a foo's current state. \t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
\t // +listMapKey=type \t Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
\t}"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down
Loading