Skip to content

feat: Add version information #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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