Skip to content

Commit

Permalink
Add support to last-action age in status
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Conforti committed Sep 1, 2024
1 parent 069d663 commit dcf4f21
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
You can install the chart using the following command:
```shell
helm upgrade -i cilium-haegress-operator --create-namespace --namespace cilium-haegress-operator oci://registry-1.docker.io/angeloxx/cilium-haegress-operator --version ${{ steps.version.outputs.VERSION }}
helm upgrade -i cilium-haegress-operator --create-namespace --namespace cilium-haegress-operator oci://registry-1.docker.io/angeloxx/cilium-haegress-operator --version ${{ steps.version.outputs.VERSION }}-helm
```
draft: false
Expand Down
4 changes: 4 additions & 0 deletions api/v2/haegressgatewaypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ type HAEgressGatewayPolicyStatus struct {

// +kubebuilder:validation:Optional
IPAddress string `json:"ipAddress,omitempty"`

// +kubebuilder:validation:Optional
LastModifiedTime metav1.Time `json:"lastModifiedTime,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="IP Address",type=string,JSONPath=`.status.ipAddress`
//+kubebuilder:printcolumn:name="Exit Node",type=string,JSONPath=`.status.exitNode`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".status.lastModifiedTime",description="Time since last modification"

// haEgressGatewayPolicy is the Schema for the haegressgatewaypolicies API
type HAEgressGatewayPolicy struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ spec:
- jsonPath: .status.exitNode
name: Exit Node
type: string
- description: Time since last modification
jsonPath: .status.lastModifiedTime
name: Age
type: date
name: v2
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -262,6 +266,9 @@ spec:
type: string
ipAddress:
type: string
lastModifiedTime:
format: date-time
type: string
policyCreated:
type: boolean
serviceCreated:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ spec:
- jsonPath: .status.exitNode
name: Exit Node
type: string
- description: Time since last modification
jsonPath: .status.lastModifiedTime
name: Age
type: date
name: v2
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -262,6 +266,9 @@ spec:
type: string
ipAddress:
type: string
lastModifiedTime:
format: date-time
type: string
policyCreated:
type: boolean
serviceCreated:
Expand Down
3 changes: 3 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -44,6 +45,7 @@ func SyncServiceWithCiliumEgressGatewayPolicy(ctx context.Context, r client.Clie
}
if haEgressGatewayPolicy.Status.IPAddress != service.Status.LoadBalancer.Ingress[0].IP {
haEgressGatewayPolicy.Status.IPAddress = service.Status.LoadBalancer.Ingress[0].IP
haEgressGatewayPolicy.Status.LastModifiedTime = metav1.Now()
if err := r.Status().Update(ctx, haEgressGatewayPolicy); err != nil {
logger.Error(err, "unable to update the HAEgressGatewayPolicy with new assigned IP")
}
Expand All @@ -57,6 +59,7 @@ func SyncServiceWithCiliumEgressGatewayPolicy(ctx context.Context, r client.Clie

if haEgressGatewayPolicy.Status.ExitNode != currentHost {
haEgressGatewayPolicy.Status.ExitNode = currentHost
haEgressGatewayPolicy.Status.LastModifiedTime = metav1.Now()
if err := r.Status().Update(ctx, haEgressGatewayPolicy); err != nil {
logger.Error(err, "unable to update the HAEgressGatewayPolicy with new assigned exitNode")
}
Expand Down

0 comments on commit dcf4f21

Please sign in to comment.