Skip to content

Commit

Permalink
Add version information (#126)
Browse files Browse the repository at this point in the history
This allows us to use build version information to help debug
issues.
  • Loading branch information
joekr committed Aug 24, 2022
1 parent 8daee8c commit f638fc5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
14 changes: 14 additions & 0 deletions cloud/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package scope

import (
"net/http"
"sync"

"github.com/go-logr/logr"
Expand All @@ -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"
Expand Down Expand Up @@ -120,6 +122,7 @@ func createVncClient(region string, ociAuthConfigProvider common.ConfigurationPr
return nil, err
}
vcnClient.SetRegion(region)
vcnClient.Interceptor = setVersionHeader()

return &vcnClient, nil
}
Expand All @@ -131,6 +134,7 @@ func createLbClient(region string, ociAuthConfigProvider common.ConfigurationPro
return nil, err
}
lbClient.SetRegion(region)
lbClient.Interceptor = setVersionHeader()

return &lbClient, nil
}
Expand All @@ -142,6 +146,7 @@ func createIdentityClient(region string, ociAuthConfigProvider common.Configurat
return nil, err
}
identityClient.SetRegion(region)
identityClient.Interceptor = setVersionHeader()

return &identityClient, nil
}
Expand All @@ -153,6 +158,7 @@ func createComputeClient(region string, ociAuthConfigProvider common.Configurati
return nil, err
}
computeClient.SetRegion(region)
computeClient.Interceptor = setVersionHeader()

return &computeClient, nil
}
Expand All @@ -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
}
}
14 changes: 7 additions & 7 deletions hack/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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[*]-}"
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f638fc5

Please sign in to comment.