diff --git a/Dockerfile b/Dockerfile index 15a02898..536e7aa0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,6 +18,7 @@ COPY cloud/ cloud/ COPY exp/ exp/ COPY feature/ feature/ COPY vendor/ vendor/ +COPY version/ version/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o manager ${package} diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index 9d481fae..824e88ab 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -17,6 +17,7 @@ limitations under the License. package scope import ( + "net/http" "sync" "github.com/go-logr/logr" @@ -25,6 +26,7 @@ import ( identityClient "github.com/oracle/cluster-api-provider-oci/cloud/services/identity" nlb "github.com/oracle/cluster-api-provider-oci/cloud/services/networkloadbalancer" "github.com/oracle/cluster-api-provider-oci/cloud/services/vcn" + "github.com/oracle/cluster-api-provider-oci/version" "github.com/oracle/oci-go-sdk/v63/common" "github.com/oracle/oci-go-sdk/v63/core" "github.com/oracle/oci-go-sdk/v63/identity" @@ -120,6 +122,7 @@ func createVncClient(region string, ociAuthConfigProvider common.ConfigurationPr return nil, err } vcnClient.SetRegion(region) + vcnClient.Interceptor = setVersionHeader() return &vcnClient, nil } @@ -131,6 +134,7 @@ func createLbClient(region string, ociAuthConfigProvider common.ConfigurationPro return nil, err } lbClient.SetRegion(region) + lbClient.Interceptor = setVersionHeader() return &lbClient, nil } @@ -142,6 +146,7 @@ func createIdentityClient(region string, ociAuthConfigProvider common.Configurat return nil, err } identityClient.SetRegion(region) + identityClient.Interceptor = setVersionHeader() return &identityClient, nil } @@ -153,6 +158,7 @@ func createComputeClient(region string, ociAuthConfigProvider common.Configurati return nil, err } computeClient.SetRegion(region) + computeClient.Interceptor = setVersionHeader() return &computeClient, nil } @@ -164,6 +170,14 @@ func createComputeManagementClient(region string, ociAuthConfigProvider common.C return nil, err } computeManagementClient.SetRegion(region) + computeManagementClient.Interceptor = setVersionHeader() return &computeManagementClient, nil } + +func setVersionHeader() func(request *http.Request) error { + return func(request *http.Request) error { + request.Header.Set("X-CAPOCI-VERSION", version.GitVersion) + return nil + } +} diff --git a/hack/version.sh b/hack/version.sh index d9006c3b..b9521882 100755 --- a/hack/version.sh +++ b/hack/version.sh @@ -74,13 +74,13 @@ version::ldflags() { ) } - add_ldflag "buildDate" "$(date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')" - add_ldflag "gitCommit" "${GIT_COMMIT}" - add_ldflag "gitTreeState" "${GIT_TREE_STATE}" - add_ldflag "gitMajor" "${GIT_MAJOR}" - add_ldflag "gitMinor" "${GIT_MINOR}" - add_ldflag "gitVersion" "${GIT_VERSION}" - add_ldflag "gitReleaseCommit" "${GIT_RELEASE_COMMIT}" + add_ldflag "BuildDate" "$(date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')" + add_ldflag "GitCommit" "${GIT_COMMIT}" + add_ldflag "GitTreeState" "${GIT_TREE_STATE}" + add_ldflag "GitMajor" "${GIT_MAJOR}" + add_ldflag "GitMinor" "${GIT_MINOR}" + add_ldflag "GitVersion" "${GIT_VERSION}" + add_ldflag "GitReleaseCommit" "${GIT_RELEASE_COMMIT}" # The -ldflags parameter takes a single string, so join the output. echo "${ldflags[*]-}" diff --git a/main.go b/main.go index dbc468c4..b4461c59 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ import ( expV1Beta1 "github.com/oracle/cluster-api-provider-oci/exp/api/v1beta1" expcontrollers "github.com/oracle/cluster-api-provider-oci/exp/controllers" "github.com/oracle/cluster-api-provider-oci/feature" + "github.com/oracle/cluster-api-provider-oci/version" "github.com/spf13/pflag" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -131,6 +132,7 @@ func main() { os.Exit(1) } + setupLog.Info("CAPOCI Version", "version", version.GitVersion) ociAuthConfigProvider, err := config.NewConfigurationProvider(authConfig) if err != nil { setupLog.Error(err, "authentication provider could not be initialised") diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..fb4ab2c7 --- /dev/null +++ b/version/version.go @@ -0,0 +1,29 @@ +package version + +// BuildDate is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var BuildDate string + +// GitCommit is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var GitCommit string + +// GitTreeState is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var GitTreeState string + +// GitMajor is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var GitMajor string + +// GitMinor is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var GitMinor string + +// GitVersion is the flag that gets set to the git version at build time +// Set by go build -ldflags "-X" flag +var GitVersion = "development" + +// GitReleaseCommit is the flag that gets set at build time +// Set by go build -ldflags "-X" flag +var GitReleaseCommit string