Skip to content

Commit

Permalink
Backport of [NET-9839] fix: add shared version submodule (#4091)
Browse files Browse the repository at this point in the history
* fix: add shared version submodule

Introduce a new submodule for sharing versioning code across the
binary-producing submodules in `consul-k8s` repo.

This is both an improvement in terms of consolidation, as well as a fix
for incorrect `control-plane` submodule pinning in the
`control-plane/cni` submodule that led to incorrect dev versions being
used in 1.4.2 and 1.4.3 (the first releases that included a valid
version of `control-plane/cni`. See #4054 comments for more context.

* build: fix non-dev prepare script chart version setting
  • Loading branch information
zalimeni committed Jun 7, 2024
1 parent 5f9a62e commit 727deb5
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .changelog/4091.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cni: fix incorrect release version due to unstable submodule pinning
```
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
export GIT_COMMIT=$(git rev-parse --short HEAD)
export GIT_DIRTY=$(test -n "$(git status --porcelain)" && echo "+CHANGES")
export GIT_IMPORT=github.com/hashicorp/consul-k8s/${{ matrix.component }}/version
export GIT_IMPORT=github.com/hashicorp/consul-k8s/version
export GOLDFLAGS="-X ${GIT_IMPORT}.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X ${GIT_IMPORT}.GitDescribe=${{ needs.get-product-version.outputs.product-version }}"
CGO_ENABLED=0 go build -o dist/${{ matrix.bin_name }} -ldflags "${GOLDFLAGS}" .
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = $(shell ./control-plane/build-support/scripts/version.sh control-plane/version/version.go)
VERSION = $(shell ./control-plane/build-support/scripts/version.sh version/version.go)
GOLANG_VERSION?=$(shell head -n 1 .go-version)
CONSUL_IMAGE_VERSION = $(shell ./control-plane/build-support/scripts/consul-version.sh charts/consul/values.yaml)
CONSUL_ENTERPRISE_IMAGE_VERSION = $(shell ./control-plane/build-support/scripts/consul-enterprise-version.sh charts/consul/values.yaml)
Expand Down
2 changes: 1 addition & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
cmdversion "github.com/hashicorp/consul-k8s/cli/cmd/version"
"github.com/hashicorp/consul-k8s/cli/common"
"github.com/hashicorp/consul-k8s/cli/common/terminal"
"github.com/hashicorp/consul-k8s/cli/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/cli"
)
Expand Down
3 changes: 3 additions & 0 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ go 1.21

toolchain go1.21.10

replace github.com/hashicorp/consul-k8s/version => ../version

require (
github.com/bgentry/speakeasy v0.1.0
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/fatih/color v1.16.0
github.com/google/go-cmp v0.6.0
github.com/hashicorp/consul-k8s/charts v0.0.0-00010101000000-000000000000
github.com/hashicorp/consul-k8s/version v0.0.0
github.com/hashicorp/consul/troubleshoot v0.3.1
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/hcp-sdk-go v0.23.1-0.20220921131124-49168300a7dc
Expand Down
2 changes: 1 addition & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os/signal"
"syscall"

"github.com/hashicorp/consul-k8s/cli/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/cli"
)
Expand Down
29 changes: 22 additions & 7 deletions control-plane/build-support/functions/10-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,13 @@ function update_version_helm {
local consul_version="$5"
local prerelease="$3"
local full_version="$2"
local full_version_k8s_for_chart_version="$2"
local full_consul_version="$5"
local full_consul_dataplane_version="$7"
local consul_dataplane_base_path="$8"
if ! test -z "$3" && test "$3" != "dev"; then
full_version="$2-$3"
full_version_k8s_for_chart_version="$2-$3"
full_consul_version="$5-$3"
full_consul_dataplane_version="$7-$3"
elif test "$3" == "dev"; then
Expand All @@ -637,6 +639,24 @@ function update_version_helm {
full_consul_dataplane_version="${7%.*}-$3"
fi

# validate script versions
if test -z "$full_version"; then
err "ERROR: full_version is empty"
return 1
fi
if test -z "$full_version_k8s_for_chart_version"; then
err "ERROR: full_version_k8s_for_chart_version is empty"
return 1
fi
if test -z "$full_consul_version"; then
err "ERROR: full_consul_version is empty"
return 1
fi
if test -z "$full_consul_dataplane_version"; then
err "ERROR: full_consul_dataplane_version is empty"
return 1
fi

sed_i ${SED_EXT} -e "s/(imageK8S:.*\/consul-k8s-control-plane:)[^\"]*/imageK8S: $4${full_version}/g" "${vfile}"
sed_i ${SED_EXT} -e "s/(version:[[:space:]]*)[^\"]*/\1${full_version}/g" "${cfile}"
sed_i ${SED_EXT} -e "s/(appVersion:[[:space:]]*)[^\"]*/\1${full_consul_version}/g" "${cfile}"
Expand Down Expand Up @@ -690,13 +710,8 @@ function set_version {
local consul_vers="$6"
local consul_dataplane_vers="$8"

status_stage "==> Updating control-plane version/version.go with version info: ${vers} "$4""
if ! update_version "${sdir}/control-plane/version/version.go" "${vers}" "$4"; then
return 1
fi

status_stage "==> Updating cli version/version.go with version info: ${vers} "$4""
if ! update_version "${sdir}/cli/version/version.go" "${vers}" "$4"; then
status_stage "==> Updating version/version.go with version info: ${vers} "$4""
if ! update_version "${sdir}/version/version.go" "${vers}" "$4"; then
return 1
fi

Expand Down
3 changes: 3 additions & 0 deletions control-plane/cni/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module github.com/hashicorp/consul-k8s/control-plane/cni

replace github.com/hashicorp/consul-k8s/version => ../../version

require (
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.2.0
github.com/hashicorp/consul-k8s/version v0.0.0
github.com/hashicorp/consul/sdk v0.13.1
github.com/hashicorp/go-hclog v1.2.2
github.com/stretchr/testify v1.8.4
Expand Down
8 changes: 5 additions & 3 deletions control-plane/cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
cniv "github.com/containernetworking/cni/pkg/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/hashicorp/consul/sdk/iptables"
"github.com/hashicorp/go-hclog"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -106,7 +107,7 @@ func parseConfig(stdin []byte) (*PluginConf, error) {

// The previous result is passed from the previously run plugin to our plugin. We do not
// do anything with the result but instead just pass it on when our plugin is finished.
if err := version.ParsePrevResult(&cfg.NetConf); err != nil {
if err := cniv.ParsePrevResult(&cfg.NetConf); err != nil {
return nil, fmt.Errorf("could not parse prevResult: %w", err)
}

Expand Down Expand Up @@ -242,7 +243,8 @@ func cmdCheck(_ *skel.CmdArgs) error {

func main() {
c := &Command{}
skel.PluginMain(c.cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("consul-cni"))
bv.BuildVersion = version.GetHumanVersion()
skel.PluginMain(c.cmdAdd, cmdCheck, cmdDel, cniv.All, bv.BuildString("consul-cni"))
}

// skipTrafficRedirection looks for annotations on the pod and determines if it should skip traffic redirection.
Expand Down
2 changes: 1 addition & 1 deletion control-plane/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
cmdTLSInit "github.com/hashicorp/consul-k8s/control-plane/subcommand/tls-init"
cmdVersion "github.com/hashicorp/consul-k8s/control-plane/subcommand/version"
webhookCertManager "github.com/hashicorp/consul-k8s/control-plane/subcommand/webhook-cert-manager"
"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/mitchellh/cli"
)

Expand Down
2 changes: 1 addition & 1 deletion control-plane/connect-inject/webhook/mesh_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/metrics"
"github.com/hashicorp/consul-k8s/control-plane/consul"
"github.com/hashicorp/consul-k8s/control-plane/namespaces"
"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"gomodules.xyz/jsonpatch/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/connect-inject/webhook/mesh_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/metrics"
"github.com/hashicorp/consul-k8s/control-plane/consul"
"github.com/hashicorp/consul-k8s/control-plane/namespaces"
"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/stretchr/testify/require"
"gomodules.xyz/jsonpatch/v2"
admissionv1 "k8s.io/api/admission/v1"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
"time"

"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/hashicorp/consul-server-connection-manager/discovery"
capi "github.com/hashicorp/consul/api"
)
Expand Down
2 changes: 1 addition & 1 deletion control-plane/consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http/httptest"
"testing"

"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
capi "github.com/hashicorp/consul/api"
"github.com/stretchr/testify/require"
)
Expand Down
3 changes: 3 additions & 0 deletions control-plane/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/hashicorp/consul-k8s/control-plane

replace github.com/hashicorp/consul-k8s/version => ../version

require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/containernetworking/cni v1.1.2
Expand All @@ -10,6 +12,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/hashicorp/consul-k8s/control-plane/cni v0.0.0-20230511143918-bd16ab83383d
github.com/hashicorp/consul-k8s/version v0.0.0
github.com/hashicorp/consul-server-connection-manager v0.1.6
github.com/hashicorp/consul/api v1.21.1
github.com/hashicorp/consul/sdk v0.13.1
Expand Down
2 changes: 1 addition & 1 deletion control-plane/helper/go-discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/hashicorp/go-discover"
discoverk8s "github.com/hashicorp/go-discover/provider/k8s"
"github.com/hashicorp/go-hclog"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"log"
"os"

"github.com/hashicorp/consul-k8s/control-plane/version"
"github.com/hashicorp/consul-k8s/version"
"github.com/mitchellh/cli"
)

Expand Down
54 changes: 0 additions & 54 deletions control-plane/version/version.go

This file was deleted.

3 changes: 3 additions & 0 deletions version/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/hashicorp/consul-k8s/version

go 1.20
File renamed without changes.

0 comments on commit 727deb5

Please sign in to comment.