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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ controller-gen:

GOLANGCI_LINT = ./bin/golangci-lint
colanci-lint-bin:
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.2)

CRD_DOCS = bin/crd-ref-docs
crd-docs-gen:
Expand Down
37 changes: 20 additions & 17 deletions apis/proxy/v1alpha1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type InstanceSpec struct {
// Resources defines the resource requirements for the HAProxy pods.
// +optional
Resources *corev1.ResourceRequirements `json:"resources"`
// InitContainers additional init containers
// +optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`
// Sidecars additional sidecar containers
// +optional
Sidecars []corev1.Container `json:"sidecars,omitempty"`
Expand Down Expand Up @@ -167,7 +170,7 @@ func (m *Metrics) AddToParser(p parser.Parser) error {
StatsOptions: &models.StatsOptions{
StatsEnable: true,
StatsURIPrefix: "/stats",
StatsRefreshDelay: ptr.To((10 * time.Second).Milliseconds()),
StatsRefreshDelay: new((10 * time.Second).Milliseconds()),
},
},
}
Expand All @@ -183,7 +186,7 @@ func (m *Metrics) AddToParser(p parser.Parser) error {
BindParams: models.BindParams{
Name: "metrics",
},
Port: ptr.To(int64(m.Port)),
Port: new(int64(m.Port)),
Address: ptr.Deref(m.Address, "0.0.0.0"),
}
configOpts = &options.ConfigurationOptions{}
Expand Down Expand Up @@ -300,12 +303,12 @@ func (g *GlobalConfiguration) Model() (models.Global, error) {
}

if g.StatsTimeout != nil {
global.StatsTimeout = ptr.To(g.StatsTimeout.Milliseconds())
global.StatsTimeout = new(g.StatsTimeout.Milliseconds())
}

if g.Reload {
global.RuntimeAPIs = append(global.RuntimeAPIs, &models.RuntimeAPI{
Address: ptr.To("/var/lib/haproxy/run/haproxy.sock"),
Address: new("/var/lib/haproxy/run/haproxy.sock"),
BindParams: models.BindParams{
ExposeFdListeners: true,
Level: "admin",
Expand Down Expand Up @@ -367,7 +370,7 @@ func (g *GlobalConfiguration) Model() (models.Global, error) {
}

if g.HardStopAfter != nil {
global.HardStopAfter = ptr.To(g.HardStopAfter.Milliseconds())
global.HardStopAfter = new(g.HardStopAfter.Milliseconds())
}

return global, global.Validate(strfmt.Default)
Expand Down Expand Up @@ -563,10 +566,10 @@ func (l *GlobalLoggingConfiguration) Model() (models.LogTarget, models.GlobalLog
}

logSendHostname := models.GlobalLogSendHostname{
Enabled: ptr.To("disabled"),
Enabled: new("disabled"),
}
if ptr.Deref(l.SendHostname, false) {
logSendHostname.Enabled = ptr.To(models.GlobalLogSendHostnameEnabledEnabled)
logSendHostname.Enabled = new(models.GlobalLogSendHostnameEnabledEnabled)
logSendHostname.Param = ptr.Deref(l.Hostname, "")
}

Expand Down Expand Up @@ -671,25 +674,25 @@ func (d *DefaultsConfiguration) Model() (models.Defaults, error) {
for name, timeout := range d.Timeouts {
switch name {
case "check":
defaults.CheckTimeout = ptr.To(timeout.Milliseconds())
defaults.CheckTimeout = new(timeout.Milliseconds())
case "client":
defaults.ClientTimeout = ptr.To(timeout.Milliseconds())
defaults.ClientTimeout = new(timeout.Milliseconds())
case "client-fin":
defaults.ClientFinTimeout = ptr.To(timeout.Milliseconds())
defaults.ClientFinTimeout = new(timeout.Milliseconds())
case "connect":
defaults.ConnectTimeout = ptr.To(timeout.Milliseconds())
defaults.ConnectTimeout = new(timeout.Milliseconds())
case "http-keep-alive":
defaults.HTTPKeepAliveTimeout = ptr.To(timeout.Milliseconds())
defaults.HTTPKeepAliveTimeout = new(timeout.Milliseconds())
case "http-request":
defaults.HTTPRequestTimeout = ptr.To(timeout.Milliseconds())
defaults.HTTPRequestTimeout = new(timeout.Milliseconds())
case "queue":
defaults.QueueTimeout = ptr.To(timeout.Milliseconds())
defaults.QueueTimeout = new(timeout.Milliseconds())
case "server":
defaults.ServerTimeout = ptr.To(timeout.Milliseconds())
defaults.ServerTimeout = new(timeout.Milliseconds())
case "server-fin":
defaults.ServerFinTimeout = ptr.To(timeout.Milliseconds())
defaults.ServerFinTimeout = new(timeout.Milliseconds())
case "tunnel":
defaults.TunnelTimeout = ptr.To(timeout.Milliseconds())
defaults.TunnelTimeout = new(timeout.Milliseconds())
default:
return defaults, fmt.Errorf("timeout %s unknown", name)
}
Expand Down
7 changes: 7 additions & 0 deletions apis/proxy/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 36 additions & 28 deletions controllers/instance/instance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/uuid"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -92,20 +91,20 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Enabled: true,
Address: "/var/lib/rsyslog/rsyslog.sock",
Facility: "local0",
SendHostname: ptr.To(true),
SendHostname: new(true),
},
TuneOptions: &proxyv1alpha1.GlobalTuneOptions{
Maxrewrite: ptr.To(int64(3000)),
Bufsize: ptr.To(int64(16384)),
Maxrewrite: new(int64(3000)),
Bufsize: new(int64(16384)),
},
HardStopAfter: &dur,
Ocsp: &proxyv1alpha1.GlobalOCSPConfiguration{
Mode: true,
MaxDelay: ptr.To(int64(3600)),
MinDelay: ptr.To(int64(300)),
MaxDelay: new(int64(3600)),
MinDelay: new(int64(300)),
HTTPProxy: &proxyv1alpha1.OcspUpdateOptionsHttpproxy{
Address: "192.168.0.10",
Port: ptr.To(int64(8000)),
Port: new(int64(8000)),
},
},
},
Expand All @@ -116,10 +115,16 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Network: proxyv1alpha1.Network{
Service: proxyv1alpha1.ServiceSpec{
Enabled: true,
Type: ptr.To(corev1.ServiceTypeLoadBalancer),
Type: new(corev1.ServiceTypeLoadBalancer),
Annotations: annotations,
},
},
InitContainers: []corev1.Container{
{Name: "init", Image: "init-image"},
},
Sidecars: []corev1.Container{
{Name: "init", Image: "init-image"},
},
},
}

Expand All @@ -146,8 +151,8 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Address: "unix@/var/lib/haproxy/run/local.sock",
Port: 9443,
Name: "https",
AcceptProxy: ptr.To(true),
Hidden: ptr.To(true),
AcceptProxy: new(true),
Hidden: new(true),
SSL: &configv1alpha1.SSL{
Enabled: true,
},
Expand Down Expand Up @@ -182,8 +187,8 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Address: "unix@/var/lib/haproxy/run/local.sock",
Port: 9443,
Name: "https",
AcceptProxy: ptr.To(true),
Hidden: ptr.To(true),
AcceptProxy: new(true),
Hidden: new(true),
SSL: &configv1alpha1.SSL{
Enabled: true,
},
Expand All @@ -208,8 +213,8 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Address: "unix@/var/lib/haproxy/run/local.sock",
Port: 9443,
Name: "https",
AcceptProxy: ptr.To(true),
Hidden: ptr.To(true),
AcceptProxy: new(true),
Hidden: new(true),
SSL: &configv1alpha1.SSL{
Enabled: true,
},
Expand Down Expand Up @@ -239,8 +244,8 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Address: "unix@/var/lib/haproxy/run/local.sock",
Port: 9443,
Name: "https",
AcceptProxy: ptr.To(true),
Hidden: ptr.To(true),
AcceptProxy: new(true),
Hidden: new(true),
SSL: &configv1alpha1.SSL{
Enabled: true,
},
Expand Down Expand Up @@ -289,7 +294,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Alpn: []string{"h2", "http/1.0"},
},
VerifyHost: "routername.namespace.svc",
Weight: ptr.To(int64(256)),
Weight: new(int64(256)),
Check: &configv1alpha1.Check{
Enabled: true,
Inter: &metav1.Duration{Duration: 5 * time.Second},
Expand Down Expand Up @@ -320,7 +325,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Ocsp: true,
OcspFile: &configv1alpha1.OcspFile{
Name: "route.name2",
Value: ptr.To(string("OCSP Response Data: ...")),
Value: new(string("OCSP Response Data: ...")),
},
},
Servers: []configv1alpha1.Server{
Expand All @@ -339,7 +344,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Alpn: []string{"h2", "http/1.0"},
},
VerifyHost: "routername.namespace.svc",
Weight: ptr.To(int64(256)),
Weight: new(int64(256)),
Check: &configv1alpha1.Check{
Enabled: true,
Inter: &metav1.Duration{Duration: 5 * time.Second},
Expand Down Expand Up @@ -370,8 +375,8 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Address: "${BIND_ADDRESS}",
Port: int32(20005),
Name: fmt.Sprintf("tcp-%d", 20005),
AcceptProxy: ptr.To(true),
Hidden: ptr.To(true),
AcceptProxy: new(true),
Hidden: new(true),
SSL: &configv1alpha1.SSL{
Enabled: true,
},
Expand Down Expand Up @@ -417,9 +422,9 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Verify: "required",
Alpn: []string{"http/1.1", "h2"},
},
Weight: ptr.To(int64(256)),
Weight: new(int64(256)),
VerifyHost: "routeName" + "." + "routeName" + ".svc",
InitAddr: ptr.To("none"),
InitAddr: new("none"),
Check: &configv1alpha1.Check{
Enabled: true,
Inter: &metav1.Duration{Duration: 500 * time.Millisecond},
Expand All @@ -440,7 +445,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Ocsp: true,
OcspFile: &configv1alpha1.OcspFile{
Name: "route.name.tcp",
Value: ptr.To(string("OCSP Response Data: ...")),
Value: new(string("OCSP Response Data: ...")),
},
},
},
Expand All @@ -454,7 +459,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Labels: labels,
},
Spec: configv1alpha1.ResolverSpec{
ParseResolvConf: ptr.To(true),
ParseResolvConf: new(true),
Hold: &configv1alpha1.Hold{
Nx: &metav1.Duration{Duration: 500 * time.Millisecond},
Valid: &metav1.Duration{Duration: 1 * time.Second},
Expand Down Expand Up @@ -493,6 +498,9 @@ var _ = Describe("Reconcile", Label("controller"), func() {
Ω(cli.Get(ctx, client.ObjectKey{Namespace: proxy.Namespace, Name: "bar-foo-haproxy"}, statefulSet)).ShouldNot(HaveOccurred())
Ω(statefulSet.Spec.Template.ObjectMeta.Labels["app.kubernetes.io/name"]).Should(Equal(proxy.Name + "-haproxy"))
Ω(statefulSet.Spec.Template.ObjectMeta.Labels["label-test"]).Should(Equal("ok"))
Ω(statefulSet.Spec.Template.Spec.InitContainers).Should(HaveLen(1))
Ω(statefulSet.Spec.Template.Spec.InitContainers[0].Name).Should(Equal(proxy.Spec.InitContainers[0].Name))
Ω(statefulSet.Spec.Template.Spec.Containers).Should(HaveLen(3))
Ω(statefulSet.Spec.Template.Spec.Containers[0].Env).Should(HaveLen(2))
})

Expand Down Expand Up @@ -600,7 +608,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
PeriodSeconds: 3,
SuccessThreshold: 4,
FailureThreshold: 5,
TerminationGracePeriodSeconds: ptr.To(int64(6)),
TerminationGracePeriodSeconds: new(int64(6)),
}

proxy.Spec.LivenessProbe = &corev1.Probe{
Expand Down Expand Up @@ -677,11 +685,11 @@ var _ = Describe("Reconcile", Label("controller"), func() {
It("remove duplicate port", func() {
feAdd1 := frontendCustomCerts2.DeepCopy()
feAdd1.Name = "additional1"
feAdd1.Spec.Binds[0].Hidden = ptr.To(false)
feAdd1.Spec.Binds[0].Hidden = new(false)

feAdd2 := frontendCustomCerts2.DeepCopy()
feAdd2.Name = "additional2"
feAdd2.Spec.Binds[0].Hidden = ptr.To(false)
feAdd2.Spec.Binds[0].Hidden = new(false)

initObjs = append(initObjs, feAdd1, feAdd2)

Expand Down
3 changes: 1 addition & 2 deletions controllers/instance/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
proxyv1alpha1 "github.com/six-group/haproxy-operator/apis/proxy/v1alpha1"
"github.com/six-group/haproxy-operator/pkg/utils"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func (r *Reconciler) reconcileServiceMonitor(ctx context.Context, instance *prox
Path: "/metrics",
RelabelConfigs: instance.Spec.Metrics.RelabelConfigs,
Interval: instance.Spec.Metrics.Interval,
Scheme: ptr.To(monitoringv1.Scheme("http")),
Scheme: new(monitoringv1.Scheme("http")),
},
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/instance/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *Reconciler) reconcileServiceEndpoints(ctx context.Context, instance *pr
for host, ip := range instance.Spec.Network.HostIPs {
addresses = append(addresses, discoveryv1.Endpoint{
Addresses: []string{ip},
NodeName: ptr.To(host),
NodeName: new(host),
})
}
sort.Slice(addresses, func(i, j int) bool {
Expand All @@ -141,9 +141,9 @@ func (r *Reconciler) reconcileServiceEndpoints(ctx context.Context, instance *pr
var ports []discoveryv1.EndpointPort
for _, port := range service.Spec.Ports {
ports = append(ports, discoveryv1.EndpointPort{
Name: ptr.To(port.Name),
Port: ptr.To(port.Port),
Protocol: ptr.To(port.Protocol),
Name: new(port.Name),
Port: new(port.Port),
Protocol: new(port.Protocol),
})
}
sort.Slice(ports, func(i, j int) bool {
Expand Down
Loading