Skip to content

Commit fdf9db7

Browse files
committed
BUILD/MAJOR: cn: update client native to v3
1 parent 21a2a57 commit fdf9db7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+498
-244
lines changed

crs/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Custom Resources
22

33
## Purpose
4-
This document aims to provide basic understanding of the workflow of writing a new custom resource for HAProxy Ingress Controller.
5-
Custom resources should be derived, whenever possible, from the [HAProxy CN (Client Native)](https://github.com/haproxytech/client-native) by reusing [HAProxy Models](https://github.com/haproxytech/client-native#haproxy-models).
6-
This guide describes how to create a CR (Custom Resource) to configure the global HAProxy section.
4+
This document aims to provide basic understanding of the workflow of writing a new custom resource for HAProxy Ingress Controller.
5+
Custom resources should be derived, whenever possible, from the [HAProxy CN (Client Native)](https://github.com/haproxytech/client-native) by reusing [HAProxy Models](https://github.com/haproxytech/client-native#haproxy-models).
6+
This guide describes how to create a CR (Custom Resource) to configure the global HAProxy section.
77

88
## Prerequisites
9-
We suppose that an HAProxy CN Model, corresponding to the kubernetes custom resource, is already available. This is the case for the HAProxy global section, that we are dealing with in this guide, where we are going to reuse the following [global model](https://github.com/haproxytech/client-native/blob/master/models/global.go).
9+
We suppose that an HAProxy CN Model, corresponding to the kubernetes custom resource, is already available. This is the case for the HAProxy global section, that we are dealing with in this guide, where we are going to reuse the following [global model](https://github.com/haproxytech/client-native/blob/master/models/global.go).
1010
If it is not the case, this needs to be done in [HAProxy Native client](https://github.com/haproxytech/client-native) by providing [swagger specification](https://github.com/haproxytech/client-native/blob/master/specification/build/haproxy_spec.yaml) of the Model and generate it via [make models](https://github.com/haproxytech/client-native/blob/master/Makefile).
1111

1212
## Directory Layout
@@ -35,9 +35,9 @@ crs
3535

3636
## Custom Resource Creation
3737
### CRD
38-
Let's start by creating the Custom Resource Definition describing the Global CR and defining the kind `Global` in the API Group `core.haproxy.org`
39-
To follow the above directory layout convention, the Global CRD should be in *crs/definitions/core/global.yaml*
40-
The following is the beginning of the CRD, full content can be found in the corresponding yaml file:
38+
Let's start by creating the Custom Resource Definition describing the Global CR and defining the kind `Global` in the API Group `core.haproxy.org`
39+
To follow the above directory layout convention, the Global CRD should be in *crs/definitions/core/global.yaml*
40+
The following is the beginning of the CRD, full content can be found in the corresponding yaml file:
4141
```
4242
apiVersion: apiextensions.k8s.io/v1
4343
kind: CustomResourceDefinition
@@ -59,10 +59,10 @@ spec:
5959
properties:
6060
spec:
6161
type: object
62-
required:
62+
required:
6363
- config
64-
properties:
65-
config:
64+
properties:
65+
config:
6666
title: Global
6767
description: HAProxy global configuration
6868
type: object
@@ -82,23 +82,23 @@ spec:
8282
type: string
8383
enum: [enabled, disabled]
8484
```
85-
The CRD is created via `apiextensions.k8s.io/v1` where the definition of a [structural schema](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) is mandatory and used for OpenAPI v3.0 validation.
85+
The CRD is created via `apiextensions.k8s.io/v1` where the definition of a [structural schema](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) is mandatory and used for OpenAPI v3.0 validation.
8686
The Custom Resource Definition is constructed by providing:
8787
- API Group Name: `core.haproxy.org`, this is the group where you can find custom resources related to HAProxy configuration.
8888
- Kind Name of the Resource: `Global` (and `globals` for plural name)
8989
- Resource Scope: in this case it is `Namespaced`
9090
- Group Version: `v1alpha1`
91-
- openAPIV3Schema: For schema validation you just copy the [global schema](https://github.com/haproxytech/client-native/blob/master/specification/models/configuration.yaml#L2) from Client Native repository and insert it in the `config` field of the CRD.
91+
- openAPIV3Schema: For schema validation you just copy the [global schema](https://github.com/haproxytech/client-native/blob/master/specification/models/configuration.yaml#L2) from Client Native repository and insert it in the `config` field of the CRD.
9292
**NB:** a helper script is available under `crs/get-crd-schema.sh` in order to automatically retreive the schema from the CN repository. The script takes the name of Client Native model as parameter (ex: `get-crd-schema.sh global`) and returns to stdout the schema after applying the necessary changes to make it a [valid schema](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation) for kubernetes.
9393

9494
### GoLang Type
95-
In this guide the API group is `core.haproxy.org` (this group is used for any resource dealing with haproxy configuration) and the API version is `alpha1v1`.
95+
In this guide the API group is `core.haproxy.org` (this group is used for any resource dealing with haproxy configuration) and the API version is `alpha1v1`.
9696
So to follow the */crs/api/<group>/<version>/* convention, the GoLang Type describing the `Global` CR should be in *crs/api/core/alpha1v1/global.go* with the following content:
9797
```
9898
package v1alpha1
9999
100100
import (
101-
"github.com/haproxytech/client-native/v2/models"
101+
"github.com/haproxytech/client-native/v3/models"
102102
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
103103
)
104104
@@ -140,18 +140,18 @@ type GlobalList struct {
140140
- The GoLang types (Global for a specific resource and GlobalList for a list of resources) need to embed `TypeMeta` and `ObjectMeta` as they are mandatory for the Kubernetes type system and any resource served by Kubernetes API.
141141
- The Spec reuses the [global configuration](https://github.com/haproxytech/client-native/blob/master/models/global.go) from HAProxy CN Models via the CR `config` field.
142142
- Additional fields can added later to Spec if need be, but any input related to the HAProxy Global section config is provided via the `config` field.
143-
- The deepcopy-gen tags are used to automatically generate deepCopy methods, required for any Kubernetes object, via the [code-generator](https://github.com/kubernetes/code-generator) tool. However Code Generators cannot generate the deepCopy method for types in external packages (in this case "github.com/haproxytech/client-native/v2/models") so this needs to be done manually by relying on the `MarshalBinary` and `UnmarshalBinary` of HAProxy Models.
143+
- The deepcopy-gen tags are used to automatically generate deepCopy methods, required for any Kubernetes object, via the [code-generator](https://github.com/kubernetes/code-generator) tool. However Code Generators cannot generate the deepCopy method for types in external packages (in this case "github.com/haproxytech/client-native/v3/models") so this needs to be done manually by relying on the `MarshalBinary` and `UnmarshalBinary` of HAProxy Models.
144144

145145
### Code Generation
146-
Custom Resources require more code and methods in order to be served by Kubernetes API but fortunately most of it can be generated automatically by Kubernetes code generators.
146+
Custom Resources require more code and methods in order to be served by Kubernetes API but fortunately most of it can be generated automatically by Kubernetes code generators.
147147
The tool we are using is [k8s.io/code-generator](https://github.com/kubernetes/code-generator) which comes with the following code generators for CRs:
148148
- deepcopy-gen: generates the new Type's DeepCopy methods.
149149
- register-gen: generates methods to register the new Type in [Kubernetes scheme](https://github.com/kubernetes/apimachinery/blob/ef51ab160544f9d05b68e132a4af0b0fab459954/pkg/runtime/scheme.go#L47) and make it known to the Kubernetes type system.
150150
- client-gen: generates the client set that will give us access to the new CR
151151
- informer-gen: generates informer methods in order to watch and react to the CR changes.
152152
- lister-gen: generates lister methods which provide a read-only caching layer for GET and LIST requests.
153153

154-
Before generating code, some global tags need to be set in the package of the versioned API group which should be in *crs/api/<group>/<version>/* directory.
154+
Before generating code, some global tags need to be set in the package of the versioned API group which should be in *crs/api/<group>/<version>/* directory.
155155
Usually this goes into the package's doc.go, so in this case it would be in *crs/api/core/alpha1v1/doc.go* with the following content:
156156
```
157157
// Package v1alpha1 contains the core v1alpha1 API group
@@ -166,7 +166,7 @@ Now you can generate all necessary code for all CRs under the */crs/api* directo
166166

167167

168168
## Custom Resource Management
169-
A custom resource manager already [exists](../controller/crmanager.go) as a single entry point for any custom resource defined inside HAProxy Ingress Controller.
169+
A custom resource manager already [exists](../controller/crmanager.go) as a single entry point for any custom resource defined inside HAProxy Ingress Controller.
170170
Its role is to be the unique delegate for all CR related task via the following CR interface:
171171
```
172172
type CR interface {

crs/api/core/v1alpha1/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package v1alpha1
1717

1818
import (
19-
"github.com/haproxytech/client-native/v2/models"
19+
"github.com/haproxytech/client-native/v3/models"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

crs/api/core/v1alpha1/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package v1alpha1
1717

1818
import (
19-
"github.com/haproxytech/client-native/v2/models"
19+
"github.com/haproxytech/client-native/v3/models"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

crs/api/core/v1alpha1/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package v1alpha1
1717

1818
import (
19-
"github.com/haproxytech/client-native/v2/models"
19+
"github.com/haproxytech/client-native/v3/models"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

crs/get-crd-schema.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
#!/usr/bin/env bash
2-
3-
set -o errexit
4-
set -o pipefail
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
55

66
command -v yq >/dev/null 2>&1 || { echo >&2 "yq not installed. Aborting."; exit 1; }
77
command -v jq >/dev/null 2>&1 || { echo >&2 "jq not installed. Aborting."; exit 1; }
8-
9-
CN_COMMIT=$(go list -m github.com/haproxytech/client-native/v2 | sed 's/^.*-//')
8+
9+
CN_COMMIT=$(go list -m github.com/haproxytech/client-native/v3 | sed 's/^.*-//')
1010

1111
if [ -z "$1" ]; then echo >&2 "No model name supplied. Aborting."; exit 1; fi
1212
if [ -z "$CN_COMMIT" ]; then echo >&2 "Unable to get git commit for CN module. Aborting."; exit 1; fi
1313

1414
curl -sk https://raw.githubusercontent.com/haproxytech/client-native/$CN_COMMIT/specification/models/configuration.yaml |
1515
yq |
16-
jq --arg MODEL $1 '.|
16+
jq --arg MODEL $1 '.|
1717
reduce paths as $p(.;
18-
if $p[0] == $MODEL and $p[-1] == "$ref" then
18+
if $p[0] == $MODEL and $p[-1] == "$ref" then
1919
setpath($p[0:-1];getpath(getpath($p) | split("/")[-1]| split(" ")))
20-
else
21-
.
20+
else
21+
.
2222
end
23-
) |
24-
.[$MODEL] |
23+
) |
24+
.[$MODEL] |
2525
walk(
26-
if type == "object" then with_entries(
26+
if type == "object" then with_entries(
2727
if .key == "x-nullable" then
2828
if .value == false then
2929
empty
3030
else
3131
.key = "nullable"
3232
end
33-
elif (.key | contains("x-")) then
34-
empty
35-
else
36-
.
37-
end
33+
elif (.key | contains("x-")) then
34+
empty
35+
else
36+
.
37+
end
3838
) else . end
3939
)' |
4040
yq -y

deploy/tests/integration/customresources/suite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"path/filepath"
2020
"testing"
2121

22-
"github.com/haproxytech/client-native/v2/models"
22+
"github.com/haproxytech/client-native/v3/models"
2323
corev1alpha1 "github.com/haproxytech/kubernetes-ingress/crs/api/core/v1alpha1"
2424
c "github.com/haproxytech/kubernetes-ingress/pkg/controller"
2525
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/env"
@@ -84,12 +84,13 @@ option dontlog-normal
8484
8585
frontend stats
8686
mode http
87-
bind *:1024
87+
bind 0:0:0:0:1024
8888
http-request set-var(txn.base) base
8989
http-request use-service prometheus-exporter if { path /metrics }
9090
stats enable
9191
stats uri /
92-
stats refresh 10s`
92+
stats refresh 10s
93+
`
9394

9495
func (suite *CustomResourceSuite) GlobalCRFixture() (eventChan chan k8s.SyncDataEvent, s store.K8s, globalCREvt k8s.SyncDataEvent) {
9596
var osArgs utils.OSArgs

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.17
55
require (
66
github.com/go-test/deep v1.0.7
77
github.com/google/renameio v1.0.1
8-
github.com/haproxytech/client-native/v2 v2.5.2-0.20211021104411-038f5cf8ec14
9-
github.com/haproxytech/config-parser/v4 v4.0.0-rc2.0.20211021093817-f9021b6ca61c
8+
github.com/haproxytech/client-native/v3 v3.1.1-0.20220510114028-57f50c20a1bf
9+
github.com/haproxytech/config-parser/v4 v4.0.0-rc2.0.20220428133329-7d0ec01198d4
1010
github.com/jessevdk/go-flags v1.4.0
1111
github.com/pires/go-proxyproto v0.6.1
1212
github.com/prometheus/client_golang v1.12.1
@@ -43,10 +43,11 @@ require (
4343
github.com/google/gofuzz v1.1.0 // indirect
4444
github.com/google/uuid v1.1.2 // indirect
4545
github.com/googleapis/gnostic v0.5.5 // indirect
46-
github.com/haproxytech/go-logger v1.0.0 // indirect
46+
github.com/haproxytech/go-logger v1.0.1-0.20211022075555-178f1cdf4d84 // indirect
4747
github.com/imdario/mergo v0.3.5 // indirect
4848
github.com/json-iterator/go v1.1.12 // indirect
4949
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
50+
github.com/kr/pretty v0.3.0 // indirect
5051
github.com/mailru/easyjson v0.7.1 // indirect
5152
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
5253
github.com/mitchellh/mapstructure v1.2.2 // indirect

0 commit comments

Comments
 (0)