Skip to content

Commit

Permalink
support optional env which dictates status check url format
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mcconnell committed Aug 18, 2022
1 parent b2fb49b commit f881183
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Kubernetes cluster domain
K6_CLUSTER_DOMAIN ?= ".cluster.local"
# Image to use for building Go
GO_BUILDER_IMG ?= "golang:1.17"
# Image URL to use all building/pushing image targets
Expand Down Expand Up @@ -78,7 +80,8 @@ uninstall: manifests kustomize
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
export K6_CLUSTER_DOMAIN=$(K6_CLUSTER_DOMAIN); \
$(KUSTOMIZE) build config/default | envsubst | kubectl apply -f -

# Delete operator from a cluster
delete: manifests kustomize
Expand All @@ -102,7 +105,8 @@ generate: controller-gen

# Build the docker image
docker-build: test
docker build . -t ${IMG} -f ${DOCKERFILE} --build-arg GO_BUILDER_IMG=${GO_BUILDER_IMG}
docker build . -t ${IMG} -f ${DOCKERFILE} \
--build-arg GO_BUILDER_IMG=${GO_BUILDER_IMG}

# Push the docker image
docker-push:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ Install the operator by running the command below:
$ make deploy
```

_note:_ by default K6 assumes your kubernetes cluster domain is .cluster.local.
If your Kubernetes cluster uses something else, e.g. `.cluster.example` you can
override this with the environment variable `K6_CLUSTER_DOMAIN`. e.g.

```bash
export K6_CLUSTER_DOMAIN=.cluster.example
make deploy
```

### Installing the CRD

The k6 operator includes one custom resource called `K6`. This will be automatically installed when you do a
Expand Down
3 changes: 3 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ spec:
- --enable-leader-election
image: controller:latest
name: manager
env:
- name: K6_CLUSTER_DOMAIN
value: $K6_CLUSTER_DOMAIN
resources:
limits:
cpu: 100m
Expand Down
13 changes: 12 additions & 1 deletion controllers/k6_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/go-logr/logr"
Expand All @@ -17,7 +18,17 @@ import (
)

func isServiceReady(log logr.Logger, service *v1.Service) bool {
resp, err := http.Get(fmt.Sprintf("http://%v.%v.svc.cluster.local:6565/v1/status", service.ObjectMeta.Name, service.ObjectMeta.Namespace))
clusterDomain := ".cluster.local"
if envClusterDomain, ok := os.LookupEnv("K6_CLUSTER_DOMAIN"); ok {
clusterDomain = envClusterDomain
}
resp, err := http.Get(
fmt.Sprintf(
"http://%s.%s.svc"+clusterDomain+":6565/v1/status",
service.ObjectMeta.Name,
service.ObjectMeta.Namespace,
),
)

if err != nil {
log.Error(err, fmt.Sprintf("failed to get status from %v", service.ObjectMeta.Name))
Expand Down

0 comments on commit f881183

Please sign in to comment.