diff --git a/.changelog/4091.txt b/.changelog/4091.txt new file mode 100644 index 0000000000..dc67979da8 --- /dev/null +++ b/.changelog/4091.txt @@ -0,0 +1,3 @@ +```release-note:bug +cni: fix incorrect release version due to unstable submodule pinning +``` diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e451bb854..99038bef56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -140,7 +140,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 }}" ${{ matrix.env }} go build -o dist/${{ matrix.bin_name }} -ldflags "${GOLDFLAGS}" -tags=${{ matrix.gotags }} . diff --git a/Makefile b/Makefile index bb665fc5e7..865618cac4 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/cli/commands.go b/cli/commands.go index 513bd6d9d7..2c2e797673 100644 --- a/cli/commands.go +++ b/cli/commands.go @@ -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" ) diff --git a/cli/go.mod b/cli/go.mod index ac05e5aaef..2429e34b6d 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -4,12 +4,15 @@ go 1.21 toolchain go1.21.4 +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.6.1 github.com/hashicorp/go-hclog v1.5.0 github.com/hashicorp/hcp-sdk-go v0.62.1-0.20230913154003-cf69c0370c54 diff --git a/cli/main.go b/cli/main.go index 133e2a28a8..86c2caecc3 100644 --- a/cli/main.go +++ b/cli/main.go @@ -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" ) diff --git a/control-plane/api-gateway/binding/validation.go b/control-plane/api-gateway/binding/validation.go index ea9208f150..02ca210294 100644 --- a/control-plane/api-gateway/binding/validation.go +++ b/control-plane/api-gateway/binding/validation.go @@ -22,7 +22,7 @@ import ( "github.com/hashicorp/consul-k8s/control-plane/api-gateway/common" "github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) var ( diff --git a/control-plane/api-gateway/common/secrets.go b/control-plane/api-gateway/common/secrets.go index 1b7d8dec33..cf05349ace 100644 --- a/control-plane/api-gateway/common/secrets.go +++ b/control-plane/api-gateway/common/secrets.go @@ -13,7 +13,7 @@ import ( "github.com/miekg/dns" corev1 "k8s.io/api/core/v1" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) var ( diff --git a/control-plane/build-support/functions/10-util.sh b/control-plane/build-support/functions/10-util.sh index 00cbf9d3fa..3f0a140f9c 100644 --- a/control-plane/build-support/functions/10-util.sh +++ b/control-plane/build-support/functions/10-util.sh @@ -621,11 +621,13 @@ function update_version_helm { local version="$2" 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 @@ -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_k8s_for_chart_version}/g" "${cfile}" sed_i ${SED_EXT} -e "s/(appVersion:[[:space:]]*)[^\"]*/\1${full_consul_version}/g" "${cfile}" @@ -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 diff --git a/control-plane/cni/go.mod b/control-plane/cni/go.mod index 46c81524f2..e27eb9ab3f 100644 --- a/control-plane/cni/go.mod +++ b/control-plane/cni/go.mod @@ -1,9 +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/control-plane v0.0.0-20240326170414-f12a82a84667 + github.com/hashicorp/consul-k8s/version v0.0.0 github.com/hashicorp/consul/sdk v0.16.1 github.com/hashicorp/go-hclog v1.5.0 github.com/stretchr/testify v1.8.4 diff --git a/control-plane/cni/go.sum b/control-plane/cni/go.sum index 1d3d58e0b9..25d890cdd4 100644 --- a/control-plane/cni/go.sum +++ b/control-plane/cni/go.sum @@ -59,8 +59,6 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/consul-k8s/control-plane v0.0.0-20240326170414-f12a82a84667 h1:5pYrzowjHkDl81CdYWZm78LTf0pujXqVWPUXic37DrA= -github.com/hashicorp/consul-k8s/control-plane v0.0.0-20240326170414-f12a82a84667/go.mod h1:7V8Rj0bFQ6l33EdNT6fys6Ga/3np0vMV/S/zv5rPuRs= github.com/hashicorp/consul/sdk v0.16.1 h1:V8TxTnImoPD5cj0U9Spl0TUxcytjcbbJeADFF07KdHg= github.com/hashicorp/consul/sdk v0.16.1/go.mod h1:fSXvwxB2hmh1FMZCNl6PwX0Q/1wdWtHJcZ7Ea5tns0s= github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= diff --git a/control-plane/cni/main.go b/control-plane/cni/main.go index 0f9a32b265..86cc211f71 100644 --- a/control-plane/cni/main.go +++ b/control-plane/cni/main.go @@ -13,8 +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" - cpv "github.com/hashicorp/consul-k8s/control-plane/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" @@ -114,7 +114,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) } @@ -264,8 +264,8 @@ func cmdCheck(_ *skel.CmdArgs) error { func main() { c := &Command{} - bv.BuildVersion = cpv.GetHumanVersion() - 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")) } // createK8sClient configures the command's Kubernetes API client if it doesn't diff --git a/control-plane/commands.go b/control-plane/commands.go index 01f5163bc3..16dbc670f7 100644 --- a/control-plane/commands.go +++ b/control-plane/commands.go @@ -27,7 +27,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" ) // Commands is the mapping of all available consul-k8s commands. diff --git a/control-plane/connect-inject/webhook/mesh_webhook.go b/control-plane/connect-inject/webhook/mesh_webhook.go index beee510b92..f568b3a907 100644 --- a/control-plane/connect-inject/webhook/mesh_webhook.go +++ b/control-plane/connect-inject/webhook/mesh_webhook.go @@ -31,7 +31,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" ) const ( diff --git a/control-plane/connect-inject/webhook/mesh_webhook_test.go b/control-plane/connect-inject/webhook/mesh_webhook_test.go index 846fd05219..a880f029c4 100644 --- a/control-plane/connect-inject/webhook/mesh_webhook_test.go +++ b/control-plane/connect-inject/webhook/mesh_webhook_test.go @@ -30,7 +30,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" ) func TestHandlerHandle(t *testing.T) { diff --git a/control-plane/connect-inject/webhookv2/mesh_webhook.go b/control-plane/connect-inject/webhookv2/mesh_webhook.go index fc54c3ece2..9676243fef 100644 --- a/control-plane/connect-inject/webhookv2/mesh_webhook.go +++ b/control-plane/connect-inject/webhookv2/mesh_webhook.go @@ -31,7 +31,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" ) const ( diff --git a/control-plane/connect-inject/webhookv2/mesh_webhook_test.go b/control-plane/connect-inject/webhookv2/mesh_webhook_test.go index faea725efe..9158449cd3 100644 --- a/control-plane/connect-inject/webhookv2/mesh_webhook_test.go +++ b/control-plane/connect-inject/webhookv2/mesh_webhook_test.go @@ -30,7 +30,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" ) func TestHandlerHandle(t *testing.T) { diff --git a/control-plane/consul/consul.go b/control-plane/consul/consul.go index 8dea334607..72a930c8fa 100644 --- a/control-plane/consul/consul.go +++ b/control-plane/consul/consul.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/consul-server-connection-manager/discovery" capi "github.com/hashicorp/consul/api" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) //go:generate mockery --name ServerConnectionManager --inpkg diff --git a/control-plane/consul/consul_test.go b/control-plane/consul/consul_test.go index 04afe08033..5f721d59fd 100644 --- a/control-plane/consul/consul_test.go +++ b/control-plane/consul/consul_test.go @@ -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" ) diff --git a/control-plane/go.mod b/control-plane/go.mod index db29e90540..160bc748fc 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -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 @@ -11,6 +13,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-20240226161840-f3842c41cb2b + 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.29.1 github.com/hashicorp/consul/proto-public v0.6.1 diff --git a/control-plane/helper/go-discover/discover.go b/control-plane/helper/go-discover/discover.go index 140586634a..6bd56b3364 100644 --- a/control-plane/helper/go-discover/discover.go +++ b/control-plane/helper/go-discover/discover.go @@ -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" diff --git a/control-plane/main.go b/control-plane/main.go index 64ccd5d43a..659485ac43 100644 --- a/control-plane/main.go +++ b/control-plane/main.go @@ -9,7 +9,7 @@ import ( "github.com/mitchellh/cli" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) func main() { diff --git a/control-plane/subcommand/connect-init/command.go b/control-plane/subcommand/connect-init/command.go index 2d245797dc..6751ffaa3e 100644 --- a/control-plane/subcommand/connect-init/command.go +++ b/control-plane/subcommand/connect-init/command.go @@ -29,7 +29,7 @@ import ( "github.com/hashicorp/consul-k8s/control-plane/namespaces" "github.com/hashicorp/consul-k8s/control-plane/subcommand/common" "github.com/hashicorp/consul-k8s/control-plane/subcommand/flags" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) const ( diff --git a/control-plane/subcommand/mesh-init/command.go b/control-plane/subcommand/mesh-init/command.go index ea03577848..5b74607a65 100644 --- a/control-plane/subcommand/mesh-init/command.go +++ b/control-plane/subcommand/mesh-init/command.go @@ -28,7 +28,7 @@ import ( "github.com/hashicorp/consul-k8s/control-plane/consul" "github.com/hashicorp/consul-k8s/control-plane/subcommand/common" "github.com/hashicorp/consul-k8s/control-plane/subcommand/flags" - "github.com/hashicorp/consul-k8s/control-plane/version" + "github.com/hashicorp/consul-k8s/version" ) const ( diff --git a/control-plane/version/fips_build.go b/control-plane/version/fips_build.go deleted file mode 100644 index 63e0e68883..0000000000 --- a/control-plane/version/fips_build.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -//go:build fips - -package version - -// This validates during compilation that we are being built with a FIPS enabled go toolchain -import ( - _ "crypto/tls/fipsonly" - "runtime" - "strings" -) - -// IsFIPS returns true if consul-k8s is operating in FIPS-140-2 mode. -func IsFIPS() bool { - return true -} - -func GetFIPSInfo() string { - str := "Enabled" - // Try to get the crypto module name - gover := strings.Split(runtime.Version(), "X:") - if len(gover) >= 2 { - gover_last := gover[len(gover)-1] - // Able to find crypto module name; add that to status string. - str = "FIPS 140-2 Enabled, crypto module " + gover_last - } - return str -} diff --git a/control-plane/version/non_fips_build.go b/control-plane/version/non_fips_build.go deleted file mode 100644 index ce99575d2c..0000000000 --- a/control-plane/version/non_fips_build.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -//go:build !fips - -package version - -// IsFIPS returns true if consul-k8s is operating in FIPS-140-2 mode. -func IsFIPS() bool { - return false -} - -func GetFIPSInfo() string { - return "" -} diff --git a/control-plane/version/version.go b/control-plane/version/version.go deleted file mode 100644 index 858716cf81..0000000000 --- a/control-plane/version/version.go +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package version - -import ( - "fmt" - "strings" -) - -var ( - // The git commit that was compiled. These will be filled in by the compiler. - GitCommit string - GitDescribe string - - // The main version number that is being run at the moment. - // - // Version must conform to the format expected by - // github.com/hashicorp/go-version for tests to work. - Version = "1.5.1" - - // A pre-release marker for the version. If this is "" (empty string) - // then it means that it is a final release. Otherwise, this is a pre-release - // such as "dev" (in development), "beta", "rc1", etc. - VersionPrerelease = "dev" -) - -// GetHumanVersion composes the parts of the version in a way that's suitable -// for displaying to humans. -func GetHumanVersion() string { - version := Version - if GitDescribe != "" { - version = GitDescribe - } - version = fmt.Sprintf("v%s", version) - - release := VersionPrerelease - if GitDescribe == "" && release == "" { - release = "dev" - } - - if IsFIPS() { - version += "+fips1402" - } - - if release != "" { - if !strings.Contains(version, "-"+release) { - // if we tagged a prerelease version then the release is in the version already - version += fmt.Sprintf("-%s", release) - } - if GitCommit != "" { - version += fmt.Sprintf(" (%s)", GitCommit) - } - } - - // Strip off any single quotes added by the git information. - return strings.Replace(version, "'", "", -1) -} diff --git a/cli/version/fips_build.go b/version/fips_build.go similarity index 100% rename from cli/version/fips_build.go rename to version/fips_build.go diff --git a/version/go.mod b/version/go.mod new file mode 100644 index 0000000000..b3772ec6bd --- /dev/null +++ b/version/go.mod @@ -0,0 +1,3 @@ +module github.com/hashicorp/consul-k8s/version + +go 1.20 diff --git a/cli/version/non_fips_build.go b/version/non_fips_build.go similarity index 100% rename from cli/version/non_fips_build.go rename to version/non_fips_build.go diff --git a/cli/version/version.go b/version/version.go similarity index 100% rename from cli/version/version.go rename to version/version.go