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

Kkavish/compatibility test #1907

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ A: The answer is simple: Service Discovery as a first class citizen. You are als
**Q: How is this different than Puppet/Chef/Ansible/Salt?**<br>
A: Configuration management tools are designed to be used in unison with Consul Template. Instead of rendering a stale configuration file, use your configuration management software to render a dynamic template that will be populated by [Consul][consul].

**Q: How does compatibility with Consul look like?
| | Consul v1.16 | Consul v1.17 | Consul v1.18 | Consul v1.16+ent | Consul v1.17+ent |
| ------------- | ------------- | ------------- | ------------- | ----------------- | ----------------- |
| CT v0.37 | ✅ | ✅ | ✅ | ✅ | ✅ |
| CT v0.36 | ✅ | ✅ | ✅ | N/A | N/A |
| CT v0.35 | ✅ | ✅ | ✅ | N/A | N/A |
| CT v0.34 | ✅ | ✅ | ✅ | N/A | N/A |

N/A = ENT tests were not supported before this version

## Contributing

To build and install Consul-Template locally, you will need to [install Go][go].
Expand Down
45 changes: 45 additions & 0 deletions compatibility_tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
ARG CONSUL_IMAGE_NAME=hashicorp/consul
ARG CONSUL_IMAGE_VERSION=1.17.1

ARG VAULT_IMAGE_NAME=hashicorp/vault
ARG VAULT_IMAGE_VERSION=1.16

ARG NOMAD_IMAGE_NAME=hashicorp/nomad
ARG NOMAD_IMAGE_VERSION=1.7

FROM ${CONSUL_IMAGE_NAME}:${CONSUL_IMAGE_VERSION} as consul
FROM ${VAULT_IMAGE_NAME}:${VAULT_IMAGE_VERSION} as vault
FROM ${NOMAD_IMAGE_NAME}:${NOMAD_IMAGE_VERSION} as nomad
FROM ubuntu:22.04

ARG CONSUL_TEMPLATE_TAG=v0.37.4
ARG GO_VERSION=1.22.1
ARG OS_ARCH=linux-amd64

RUN apt-get update -y -q && apt-get upgrade -y -q && \
apt-get install tar git wget make rsyslog sudo curl -y && \
curl -sSL https://get.docker.com/ | sh

RUN rm -rf /usr/local/go && wget https://go.dev/dl/go${GO_VERSION}.${OS_ARCH}.tar.gz && tar -C /usr/local -xzf go${GO_VERSION}.${OS_ARCH}.tar.gz

RUN git clone https://github.com/hashicorp/consul-template.git
RUN cd consul-template && git fetch --all --tags && git checkout tags/${CONSUL_TEMPLATE_TAG} -b ${CONSUL_TEMPLATE_TAG}-branch

COPY --from=consul /bin/consul /bin/consul
COPY --from=vault /bin/vault /bin/vault
COPY --from=nomad /bin/nomad /bin/nomad

ADD rsyslog.conf /etc/rsyslog.conf
ADD run_tests.sh /run_tests.sh
#ADD run_nomad.sh /run_nomad.sh

RUN chmod +x /run_tests.sh
RUN chmod +x /run_nomad.sh
RUN sed -i '/imklog/s/^/#/' /etc/rsyslog.conf

WORKDIR /consul-template

ENV PATH="${PATH}:/bin:/usr/local/go/bin:/usr/local/go/src"
ENV GOPRIVATE="github.com/hashicorp/*"

CMD ["/run_tests.sh"]
63 changes: 63 additions & 0 deletions compatibility_tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
CONSUL_CE_IMAGE = hashicorp/consul
CONSUL_CE_VERSIONS = 1.18 1.17 1.16 1.15

CONSUL_ENT_IMAGE = hashicorp/consul-enterprise
CONSUL_ENT_VERSIONS = 1.17-ent 1.16-ent 1.15-ent

CONSUL_TEMPLATE_TAG = v0.34.0

build-ce-images:
@echo "==> running build-ce-images"
for version in $(CONSUL_CE_VERSIONS); do \
docker build -t ct-consul-compat-$$version \
--build-arg CONSUL_IMAGE_VERSION=$$version \
--build-arg CONSUL_IMAGE_NAME=${CONSUL_CE_IMAGE} \
--build-arg CONSUL_TEMPLATE_TAG=${CONSUL_TEMPLATE_TAG} \
--no-cache .; \
done

.PHONY: .build-ce-images

build-ent-images:
@echo "==> running build-ent-images"
for version in $(CONSUL_ENT_VERSIONS); do \
docker build -t ct-consul-compat-$$version \
--build-arg CONSUL_IMAGE_VERSION=$$version \
--build-arg CONSUL_IMAGE_NAME=${CONSUL_ENT_IMAGE} \
--build-arg CONSUL_TEMPLATE_TAG=${CONSUL_TEMPLATE_TAG} \
--no-cache .; \
done

.PHONY: .build-ent-images

test-compat-ce:
@echo "==> running test-compat-ce"
for version in $(CONSUL_CE_VERSIONS); do \
docker run --privileged --init ct-consul-compat-$$version; \
done

.PHONY: test-compat-ce

test-compat-ent:
@echo "==> running test-compat-ent"
for version in $(CONSUL_ENT_VERSIONS); do \
docker run --privileged -e CONSUL_LICENSE=$(CONSUL_LICENSE) --init ct-consul-compat-$$version; \
done

.PHONY: test-compat-ent

test-compat:
@echo "==> running run"
build-ce-images
test-compat-ce
build-ent-images
test-compat-ent
done

.PHONY: test-compat

clean:
@echo "==> running clean"
docker system prune

.PHONY: clean
23 changes: 23 additions & 0 deletions compatibility_tests/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Run Consul Template Compatibility Tests

## Prerequisites

### Check whether the cgroup2 filesystem is mounted with following mount configuration:
```mount | grep cgroup```

### If not, mount the cgroup2 filesystem with the following command:
```sudo mount -t cgroup2 -o rw,nosuid,nodev,noexec,relatime,memory_recursiveprot none /sys/fs/cgroup```

## How to run the compatibility tests
1. Update the versions of Consul and tag of Consul Template in Makefile. For ENT builds, set an env variable `CONSUL_LICENSE` before running the commands.
2. Run the following command:
```shell
cd compatibility_tests
make test-compat
```
3. The test results will be displayed on the console.
4. If the tests fail, check the container for the logs.
5. To clean up the containers, run the following command:
```shell
make clean
```
59 changes: 59 additions & 0 deletions compatibility_tests/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html
#
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

module(load="imuxsock") # provides support for local system logging
#module(load="immark") # provides --MARK-- message capability

# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")

# provides TCP syslog reception
#module(load="imtcp")
#input(type="imtcp" port="514")

# provides kernel logging support and enable non-kernel klog messages
module(load="imklog" permitnonkernelfacility="on")

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf
9 changes: 9 additions & 0 deletions compatibility_tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

sudo mkdir /sys/fs/cgroup/init && \
for p in `cat /sys/fs/cgroup/cgroup.procs`; do echo $p | sudo tee /sys/fs/cgroup/init/cgroup.procs || true; done

dockerd &
rsyslogd -n &

go test -count=1 -timeout=30s -parallel=20 -tags="${GOTAGS}" `go list ./... | grep -v github.com/hashicorp/consul-template/watch | grep -v github.com/hashicorp/consul-template/version` ${TESTARGS}