Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
792bf88
Added haproxy sidecar in its most basic form
Jun 3, 2021
5914b30
Altered auth to oidc from gdc
Jul 1, 2021
562db2d
Removing GAQ logic from VCL
Jul 1, 2021
6ee3c0b
Updates to haproxy.cfg based on Anton H's feedback
Jul 1, 2021
4e79d45
Fixed logging so it's all going to stdout
Jul 1, 2021
51db32c
Refactored volumes and containers into their own singleton structs
Jul 1, 2021
9dfadcf
Removing "fix" from makefile
Jul 1, 2021
0a76f62
Removing "fix" from makefile
Jul 1, 2021
57625cd
Added haproxy scripts volume to mount scripts for haproxy
Jul 1, 2021
852e860
First working version of haproxy and VCL config
Jul 2, 2021
5f0f93e
Merge branch 'main' into 32-haproxy-ssl-backends
Jul 2, 2021
306d086
Defaulting HaproxySidecar object so nil checks aren't required
Jul 2, 2021
163a5e1
Updated dependencies
Jul 2, 2021
055c7bf
Removed backend checking logic in VCL as it's not required for haproxy
Jul 6, 2021
b59bc00
Added haproxy dashboard and hooked in
Jul 7, 2021
806a4e3
Added logic to disable haproxy dashboard when appropriate
Jul 7, 2021
2272532
Updated kind node images for k8s versions 1.20 and 1.19
Jul 9, 2021
4c6fddc
Updated kind node docker images based on 0.11.1 release notes
Jul 12, 2021
7025912
WIP checkin so I can swap branches
Sep 21, 2021
e2fdbfd
Merge branch 'main' into 32-haproxy-ssl-backends
Sep 21, 2021
80b3062
Merge branch 'main' into 32-haproxy-ssl-backends
Sep 22, 2021
d8d3f37
WIP checkin. grabbing main
Nov 1, 2021
22437e1
Merge branch 'main' into 32-haproxy-ssl-backends
Nov 1, 2021
377396f
Refactored logic to write haproxy config in varnish controller
Nov 2, 2021
7c8dbe0
WIP: Refactored some of the volume logic
Jan 15, 2022
6bcb167
Merge branch 'main' into 32-haproxy-ssl-backends
May 12, 2022
c74081b
Added HaproxySidecarStatus field to VarnishClusterStatus
May 23, 2022
5718d16
Merge branch 'main' into 32-haproxy-ssl-backends
May 23, 2022
3f18cf5
Fixed oversight in removal of haproxy configmap name from CRD
May 23, 2022
68bcd38
Added several new fields to the haproxy template
May 24, 2022
3fed6bb
Work in progress backup
Jul 1, 2022
7e511a5
Added haproxy-init container
Jul 12, 2022
f16d73e
Upgraded controller-gen to 0.9.2
Jul 12, 2022
d08d216
WIP: needed to use runAsUser to get haproxy and varnish to run as the…
Sep 29, 2022
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 .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
./Jenkinsfile
./Makefile
./README.md
./bin
# ./bin
./varnish-operator
./vendor
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ _output
*.swp
*.swo
_book
skaffold.yaml
*.local
2 changes: 1 addition & 1 deletion Dockerfile.controller
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends varnish
FROM debian:bullseye-slim
LABEL maintainer="Alex Lytvynenko <[email protected]>, Tomash Sidei <[email protected]>"

RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libc6 libedit2 libncursesw6 libtinfo6 libvarnishapi2 \
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends libc6 libedit2 libncursesw6 libtinfo6 libvarnishapi2 procps \
&& rm -rf /var/lib/apt/lists/* \
/etc/varnish/* \
&& adduser --quiet --system --no-create-home --home /nonexistent --group varnish \
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.haproxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM haproxytech/haproxy-debian:2.7

RUN apt-get update && apt-get upgrade -y \
&& adduser --quiet --system --no-create-home --home /nonexistent --group varnish \
&& rm -rf /var/lib/apt/lists/*

USER varnish
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ VARNISH_METRICS_IMG ?= ${VARNISH_METRICS_PUBLISH_IMG}-dev
NAMESPACE ?= "default"
CRD_OPTIONS ?= "crd:crdVersions=v1"

KUSTOMIZE = $(shell pwd)/bin/kustomize
ifeq (, $(wildcard $KUSTOMIZE))
KUSTOMIZE = $(shell which kustomize)
endif

# ifeq (, $(wildcard $KUSTOMIZE))
# $(error kustomize must exist)
# endif

# all: test varnish-operator
all: test varnish-operator varnish-controller

Expand Down Expand Up @@ -149,16 +158,20 @@ e2e-tests:
KUBECONFIG=$(ROOT_DIR)e2e-tests-kubeconfig go test ./tests
sh $(ROOT_DIR)hack/delete_dev_cluster.sh

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize:
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests kustomize
ifeq ($(shell yq --version | cut -d" " -f3 | cut -d"." -f1), 3)
yq w -i config/manager/deployment.yaml 'spec.template.spec.containers(name==varnish-operator).env(name==CONTAINER_IMAGE).value' $(PUBLISH_IMG)
yq w -i config/manifests/bases/varnish-operator.clusterserviceversion.yaml 'metadata.annotations.containerImage' $(PUBLISH_IMG)
yq w -i config/manifests/bases/varnish-operator.clusterserviceversion.yaml 'metadata.annotations.createdAt' $(date +"%Y-%m-%d")
else
yq e '(.spec.template.spec.containers[] | select(.name == "varnish-operator") | .env[] | select(.name == "CONTAINER_IMAGE") | .value) = "'$(PUBLISH_IMG)'"' -i config/manager/deployment.yaml
yq e '.metadata.annotations.containerImage = "'$(PUBLISH_IMG)'" | .metadata.annotations.createdAt = "'$(date +"%Y-%m-%d")'"' -i config/manifests/bases/varnish-operator.clusterserviceversion.yaml
endif
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(PUBLISH_IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
Expand Down
36 changes: 36 additions & 0 deletions api/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,45 @@ func defaultVarnishClusterSpec(in *VarnishClusterSpec) {
if in.Backend.ZoneBalancing == nil {
in.Backend.ZoneBalancing = &VarnishClusterBackendZoneBalancing{}
}

DefaultHaproxySidecar(in.HaproxySidecar)

defaultVarnishZoneBalancingType(in.Backend.ZoneBalancing)
}

func DefaultHaproxySidecar(haproxySidecar *HaproxySidecar) {
if haproxySidecar == nil {
haproxySidecar = &HaproxySidecar{
Enabled: false,
}
} else if haproxySidecar.Enabled {
if haproxySidecar.MaxConnections == nil {
haproxySidecar.MaxConnections = proto.Int32(64)
}
if haproxySidecar.ConnectTimeout == nil {
haproxySidecar.ConnectTimeout = proto.Int32(5000)
}
if haproxySidecar.ClientTimeout == nil {
haproxySidecar.ClientTimeout = proto.Int32(50000)
}
if haproxySidecar.ServerTimeout == nil {
haproxySidecar.ServerTimeout = proto.Int32(50000)
}
if haproxySidecar.StatRefreshRate == nil {
haproxySidecar.StatRefreshRate = proto.Int32(10)
}
if haproxySidecar.BackendAdditionalFlags == "" {
haproxySidecar.BackendAdditionalFlags = "none"
}
if haproxySidecar.BackendServerMaxAgeHeader == nil {
haproxySidecar.BackendServerMaxAgeHeader = proto.Int32(31536000)
}
if haproxySidecar.BackendServerPort == nil {
haproxySidecar.BackendServerPort = proto.Int32(443)
}
}
}

func defaultVarnish(in *VarnishClusterVarnish) {
if in.ImagePullPolicy == "" {
in.ImagePullPolicy = v1.PullAlways
Expand Down
53 changes: 46 additions & 7 deletions api/v1alpha1/varnishcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ const (
VarnishClusterBackendZoneBalancingTypeDisabled = "disabled"
VarnishClusterBackendZoneBalancingTypeAuto = "auto"
VarnishClusterBackendZoneBalancingTypeThresholds = "thresholds"

HaproxyContainerName = "haproxy-sidecar"
HaproxyConfigFileName = "haproxy.cfg"
HaproxyConfigDir = "/usr/local/etc/haproxy"
HaproxyConfigVolume = "haproxy-config"
HaproxyMetricsPort = 8404
HaproxyMetricsPortName = "haproxy-metrics"
HaproxyScriptsVolume = "haproxy-scripts"
)

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -96,7 +104,29 @@ type VarnishClusterSpec struct {
// +kubebuilder:validation:Enum=debug;info;warn;error;dpanic;panic;fatal
LogLevel string `json:"logLevel,omitempty"`
// +kubebuilder:validation:Enum=json;console
LogFormat string `json:"logFormat,omitempty"`
LogFormat string `json:"logFormat,omitempty"`
HaproxySidecar *HaproxySidecar `json:"haproxySidecar,omitempty"`
}

type HaproxySidecar struct {
Enabled bool `json:"enabled,omitempty"`
Image string `json:"image,omitempty"`
// +kubebuilder:validation:Enum=Always;Never;IfNotPresent
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullSecret string `json:"imagePullSecret,omitempty"`
Resources v1.ResourceRequirements `json:"resources,omitempty"`
MaxConnections *int32 `json:"maxConnections,omitempty"`
ConnectTimeout *int32 `json:"connectTimeout,omitempty"` // in millis, 5000 default
ClientTimeout *int32 `json:"clientTimeout,omitempty"` // in millis, 50000 default
ServerTimeout *int32 `json:"serverTimeout,omitempty"` // in millis, 50000 default
StatRefreshRate *int32 `json:"statRefreshRate,omitempty"` // in seconds, 10 default
EnableFrontendMetrics bool `json:"enableFrontendMetrics,omitempty"`
BackendAdditionalFlags string `json:"backendAdditionalFlags,omitempty"`
BackendServerHostHeader string `json:"backendServerHostHeader"`
BackendServerMaxAgeHeader *int32 `json:"backendServerMaxAgeHeader,omitempty"`
BackendServerPort *int32 `json:"backendServerPort,omitempty"`
BackendServers []string `json:"backendServers"`
HttpChk []string `json:"httpchk,omitempty"`
}

type VarnishClusterUpdateStrategyType string
Expand Down Expand Up @@ -241,19 +271,28 @@ type VarnishClusterMonitoringGrafanaDashboard struct {

// VarnishClusterStatus defines the observed state of VarnishCluster
type VarnishClusterStatus struct {
VCL VCLStatus `json:"vcl"`
VarnishArgs string `json:"varnishArgs,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
VarnishPodsSelector string `json:"varnishPodsSelector,omitempty"`
VCL VCLStatus `json:"vcl"`
HAProxy HaproxySidecarStatus `json:"haproxy"`
VarnishArgs string `json:"varnishArgs,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
VarnishPodsSelector string `json:"varnishPodsSelector,omitempty"`
}

// VCLStatus describes the VCL versions status
type VCLStatus struct {
type ConfigMapStatus struct {
Version *string `json:"version,omitempty"`
ConfigMapVersion string `json:"configMapVersion"`
Availability string `json:"availability"`
}

// VCLStatus describes the VCL versions status
type VCLStatus struct {
ConfigMapStatus `json:",inline"`
}

type HaproxySidecarStatus struct {
ConfigMapStatus `json:",inline"`
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

Expand Down
109 changes: 104 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

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

37 changes: 37 additions & 0 deletions cmd/varnish-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"time"

"github.com/ibm/varnish-operator/pkg/names"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/ibm/varnish-operator/api/v1alpha1"
"github.com/ibm/varnish-operator/pkg/logger"
Expand Down Expand Up @@ -69,6 +77,11 @@ func main() {
log.Fatalf("could not load rest client config. Error: %s", err)
}

if _, ok := os.LookupEnv("INIT_CONTAINER"); ok {
initHaproxyConfig(clientConfig, logr, varnishControllerConfig)
return
}

vMetrics := varnishMetrics.NewVarnishControllerMetrics()
controllerMetrics.Registry.MustRegister(vMetrics.VCLCompilationError)

Expand Down Expand Up @@ -107,3 +120,27 @@ func main() {
logr.With(err).Fatalf("Failed to start manager")
}
}

func initHaproxyConfig(clientConfig *rest.Config, logr *logger.Logger, varnishControllerConfig *config.Config) {
cs, err := kubernetes.NewForConfig(clientConfig)
if err != nil {
logr.With(zap.Error(err)).Fatalf("unable to create k8s client")
}
haproxyConfigMapName := names.HaproxyConfigMap(varnishControllerConfig.VarnishClusterName)
configFound := false
for !configFound {
logr.Infof("attempting to retrieve configmap: %s", haproxyConfigMapName)
configMaps := cs.CoreV1().ConfigMaps(varnishControllerConfig.Namespace)
if haproxyConfigMap, err := configMaps.Get(context.Background(), haproxyConfigMapName, metav1.GetOptions{}); err == nil {
cfgData := haproxyConfigMap.Data[v1alpha1.HaproxyConfigFileName]
haproxyConfigFileName := v1alpha1.HaproxyConfigDir + "/" + v1alpha1.HaproxyConfigFileName
if err := os.WriteFile(haproxyConfigFileName, []byte(cfgData), 0644); err != nil {
logr.With(zap.Error(err)).Fatalf("unable to write haproxy config file: %s", haproxyConfigFileName)
}
logr.Infof("haproxy config has been written\n%s", cfgData)
configFound = true
} else {
time.Sleep(2 * time.Second)
}
}
}
Loading