Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addresses fields to status #52

Merged
merged 4 commits into from
Jan 18, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
- run: make test

lint:
Expand All @@ -18,10 +18,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
- uses: golangci/golangci-lint-action@v3
with:
version: v1.53
version: v1.55

integration:
runs-on: ubuntu-latest
Expand All @@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.21'
- name: Setup
run: |
kubectl create namespace nginx-operator-system
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.21 as builder
WORKDIR /workspace
# Copy the Go Modules and Go source code
COPY ./ ./
Expand Down
10 changes: 8 additions & 2 deletions api/v1alpha1/nginx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
// +kubebuilder:printcolumn:name="Current",type=integer,JSONPath=`.status.currentReplicas`
// +kubebuilder:printcolumn:name="Desired",type=integer,JSONPath=`.spec.replicas`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:printcolumn:name="Ingress IPs",type=string,JSONPath=`.status.ingresses[*].ips[*]`
// +kubebuilder:printcolumn:name="Service IPs",type=string,JSONPath=`.status.services[*].ips[*]`

// Nginx is the Schema for the nginxes API
type Nginx struct {
Expand Down Expand Up @@ -262,12 +264,16 @@ type DeploymentStatus struct {

type ServiceStatus struct {
// Name is the name of the Service created by nginx
Name string `json:"name"`
Name string `json:"name"`
IPs []string `json:"ips,omitempty"`
Hostnames []string `json:"hostnames,omitempty"`
}

type IngressStatus struct {
// Name is the name of the Ingress created by nginx
Name string `json:"name"`
Name string `json:"name"`
IPs []string `json:"ips,omitempty"`
Hostnames []string `json:"hostnames,omitempty"`
}

func init() {
Expand Down
22 changes: 22 additions & 0 deletions config/crd/bases/nginx.tsuru.io_nginxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .status.ingresses[*].ips[*]
name: Ingress IPs
type: string
- jsonPath: .status.services[*].ips[*]
name: Service IPs
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down Expand Up @@ -5680,6 +5686,14 @@ spec:
ingresses:
items:
properties:
hostnames:
items:
type: string
type: array
ips:
items:
type: string
type: array
name:
description: Name is the name of the Ingress created by nginx
type: string
Expand All @@ -5693,6 +5707,14 @@ spec:
services:
items:
properties:
hostnames:
items:
type: string
type: array
ips:
items:
type: string
type: array
name:
description: Name is the name of the Service created by nginx
type: string
Expand Down
54 changes: 49 additions & 5 deletions controllers/nginx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"reflect"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -51,6 +52,8 @@ func (r *NginxReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&nginxv1alpha1.Nginx{}).
Owns(&appsv1.Deployment{}).
Owns(&networkingv1.Ingress{}).
Owns(&corev1.Service{}).
Complete(r)
}

Expand Down Expand Up @@ -239,6 +242,12 @@ func (r *NginxReconciler) reconcileIngress(ctx context.Context, nginx *nginxv1al
return nil
}

for key, value := range currentIngress.Annotations {
if newIngress.Annotations[key] == "" {
newIngress.Annotations[key] = value
}
}

newIngress.ResourceVersion = currentIngress.ResourceVersion
newIngress.Finalizers = currentIngress.Finalizers

Expand All @@ -250,8 +259,13 @@ func shouldUpdateIngress(currentIngress, newIngress *networkingv1.Ingress) bool
return false
}

return !reflect.DeepEqual(currentIngress.Annotations, newIngress.Annotations) ||
!reflect.DeepEqual(currentIngress.Labels, newIngress.Labels) ||
for key, value := range newIngress.Annotations {
if currentIngress.Annotations[key] != value {
return true
}
}

return !reflect.DeepEqual(currentIngress.Labels, newIngress.Labels) ||
!reflect.DeepEqual(currentIngress.Spec, newIngress.Spec)
}

Expand Down Expand Up @@ -361,9 +375,24 @@ func listServices(ctx context.Context, c client.Client, nginx *nginxv1alpha1.Ngi

var services []nginxv1alpha1.ServiceStatus
for _, s := range serviceList.Items {
services = append(services, nginxv1alpha1.ServiceStatus{
svc := nginxv1alpha1.ServiceStatus{
Name: s.Name,
})
}

for _, ingStatus := range s.Status.LoadBalancer.Ingress {
if ingStatus.IP != "" {
svc.IPs = append(svc.IPs, ingStatus.IP)
}

if ingStatus.Hostname != "" {
svc.Hostnames = append(svc.Hostnames, ingStatus.Hostname)
}
}

slices.Sort(svc.IPs)
slices.Sort(svc.Hostnames)

services = append(services, svc)
}

sort.Slice(services, func(i, j int) bool {
Expand All @@ -386,7 +415,22 @@ func listIngresses(ctx context.Context, c client.Client, nginx *nginxv1alpha1.Ng

var ingresses []nginxv1alpha1.IngressStatus
for _, i := range ingressList.Items {
ingresses = append(ingresses, nginxv1alpha1.IngressStatus{Name: i.Name})
ing := nginxv1alpha1.IngressStatus{Name: i.Name}

for _, ingStatus := range i.Status.LoadBalancer.Ingress {
if ingStatus.IP != "" {
ing.IPs = append(ing.IPs, ingStatus.IP)
}

if ingStatus.Hostname != "" {
ing.Hostnames = append(ing.Hostnames, ingStatus.Hostname)
}
}

slices.Sort(ing.IPs)
slices.Sort(ing.Hostnames)

ingresses = append(ingresses, ing)
}

sort.Slice(ingresses, func(i, j int) bool {
Expand Down
Loading
Loading