Skip to content

Commit f638fc5

Browse files
authored
Add version information (#126)
This allows us to use build version information to help debug issues.
1 parent 8daee8c commit f638fc5

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ COPY cloud/ cloud/
1818
COPY exp/ exp/
1919
COPY feature/ feature/
2020
COPY vendor/ vendor/
21+
COPY version/ version/
2122

2223
# Build
2324
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -ldflags "${LDFLAGS} -extldflags '-static'" -o manager ${package}

cloud/scope/clients.go

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package scope
1818

1919
import (
20+
"net/http"
2021
"sync"
2122

2223
"github.com/go-logr/logr"
@@ -25,6 +26,7 @@ import (
2526
identityClient "github.com/oracle/cluster-api-provider-oci/cloud/services/identity"
2627
nlb "github.com/oracle/cluster-api-provider-oci/cloud/services/networkloadbalancer"
2728
"github.com/oracle/cluster-api-provider-oci/cloud/services/vcn"
29+
"github.com/oracle/cluster-api-provider-oci/version"
2830
"github.com/oracle/oci-go-sdk/v63/common"
2931
"github.com/oracle/oci-go-sdk/v63/core"
3032
"github.com/oracle/oci-go-sdk/v63/identity"
@@ -120,6 +122,7 @@ func createVncClient(region string, ociAuthConfigProvider common.ConfigurationPr
120122
return nil, err
121123
}
122124
vcnClient.SetRegion(region)
125+
vcnClient.Interceptor = setVersionHeader()
123126

124127
return &vcnClient, nil
125128
}
@@ -131,6 +134,7 @@ func createLbClient(region string, ociAuthConfigProvider common.ConfigurationPro
131134
return nil, err
132135
}
133136
lbClient.SetRegion(region)
137+
lbClient.Interceptor = setVersionHeader()
134138

135139
return &lbClient, nil
136140
}
@@ -142,6 +146,7 @@ func createIdentityClient(region string, ociAuthConfigProvider common.Configurat
142146
return nil, err
143147
}
144148
identityClient.SetRegion(region)
149+
identityClient.Interceptor = setVersionHeader()
145150

146151
return &identityClient, nil
147152
}
@@ -153,6 +158,7 @@ func createComputeClient(region string, ociAuthConfigProvider common.Configurati
153158
return nil, err
154159
}
155160
computeClient.SetRegion(region)
161+
computeClient.Interceptor = setVersionHeader()
156162

157163
return &computeClient, nil
158164
}
@@ -164,6 +170,14 @@ func createComputeManagementClient(region string, ociAuthConfigProvider common.C
164170
return nil, err
165171
}
166172
computeManagementClient.SetRegion(region)
173+
computeManagementClient.Interceptor = setVersionHeader()
167174

168175
return &computeManagementClient, nil
169176
}
177+
178+
func setVersionHeader() func(request *http.Request) error {
179+
return func(request *http.Request) error {
180+
request.Header.Set("X-CAPOCI-VERSION", version.GitVersion)
181+
return nil
182+
}
183+
}

hack/version.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ version::ldflags() {
7474
)
7575
}
7676

77-
add_ldflag "buildDate" "$(date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')"
78-
add_ldflag "gitCommit" "${GIT_COMMIT}"
79-
add_ldflag "gitTreeState" "${GIT_TREE_STATE}"
80-
add_ldflag "gitMajor" "${GIT_MAJOR}"
81-
add_ldflag "gitMinor" "${GIT_MINOR}"
82-
add_ldflag "gitVersion" "${GIT_VERSION}"
83-
add_ldflag "gitReleaseCommit" "${GIT_RELEASE_COMMIT}"
77+
add_ldflag "BuildDate" "$(date ${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"} -u +'%Y-%m-%dT%H:%M:%SZ')"
78+
add_ldflag "GitCommit" "${GIT_COMMIT}"
79+
add_ldflag "GitTreeState" "${GIT_TREE_STATE}"
80+
add_ldflag "GitMajor" "${GIT_MAJOR}"
81+
add_ldflag "GitMinor" "${GIT_MINOR}"
82+
add_ldflag "GitVersion" "${GIT_VERSION}"
83+
add_ldflag "GitReleaseCommit" "${GIT_RELEASE_COMMIT}"
8484

8585
# The -ldflags parameter takes a single string, so join the output.
8686
echo "${ldflags[*]-}"

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
expV1Beta1 "github.com/oracle/cluster-api-provider-oci/exp/api/v1beta1"
2828
expcontrollers "github.com/oracle/cluster-api-provider-oci/exp/controllers"
2929
"github.com/oracle/cluster-api-provider-oci/feature"
30+
"github.com/oracle/cluster-api-provider-oci/version"
3031
"github.com/spf13/pflag"
3132
"k8s.io/apimachinery/pkg/runtime"
3233
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -131,6 +132,7 @@ func main() {
131132
os.Exit(1)
132133
}
133134

135+
setupLog.Info("CAPOCI Version", "version", version.GitVersion)
134136
ociAuthConfigProvider, err := config.NewConfigurationProvider(authConfig)
135137
if err != nil {
136138
setupLog.Error(err, "authentication provider could not be initialised")

version/version.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package version
2+
3+
// BuildDate is the flag that gets set at build time
4+
// Set by go build -ldflags "-X" flag
5+
var BuildDate string
6+
7+
// GitCommit is the flag that gets set at build time
8+
// Set by go build -ldflags "-X" flag
9+
var GitCommit string
10+
11+
// GitTreeState is the flag that gets set at build time
12+
// Set by go build -ldflags "-X" flag
13+
var GitTreeState string
14+
15+
// GitMajor is the flag that gets set at build time
16+
// Set by go build -ldflags "-X" flag
17+
var GitMajor string
18+
19+
// GitMinor is the flag that gets set at build time
20+
// Set by go build -ldflags "-X" flag
21+
var GitMinor string
22+
23+
// GitVersion is the flag that gets set to the git version at build time
24+
// Set by go build -ldflags "-X" flag
25+
var GitVersion = "development"
26+
27+
// GitReleaseCommit is the flag that gets set at build time
28+
// Set by go build -ldflags "-X" flag
29+
var GitReleaseCommit string

0 commit comments

Comments
 (0)