Skip to content

Commit

Permalink
fix: self-reported version not correct (#387)
Browse files Browse the repository at this point in the history
The release process was changed after v1.9.1 to use `ldflags` with `-X`
to dynamically set the version in the binary.

This silently failed because with `-X` you can only change the value of
_variables_, not _constants_ but our `providerVersion` was a constant
beforehand. You also need to provide the full import path, and not the
relative path from where you build the binary.

I also changed the default value to "unknown" to better reflect the
value if the binary was not properly built.
  • Loading branch information
apricote authored Mar 9, 2023
1 parent a8bcc62 commit c5160f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ builds:
- amd64
binary: hcloud-cloud-controller-manager
ldflags:
- "-s -w -X hcloud.providerVersion={{ if not .IsSnapshot }}v{{ end }}{{ .Version }}"
- "-s -w -X github.com/hetznercloud/hcloud-cloud-controller-manager/hcloud.providerVersion={{ if not .IsSnapshot }}v{{ end }}{{ .Version }}"

archives:
- id: deployment-yamls
Expand Down
4 changes: 3 additions & 1 deletion hcloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ const (
hcloudMetricsAddress = ":8233"
nodeNameENVVar = "NODE_NAME"
providerName = "hcloud"
providerVersion = "v1.9.1"
)

// providerVersion is set by the build process using -ldflags -X
var providerVersion = "unknown"

type cloud struct {
client *hcloud.Client
instances *instances
Expand Down

0 comments on commit c5160f8

Please sign in to comment.