Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 0e32271

Browse files
authored
Merge pull request #377 from kubernetes-sigs/fix-user-agent
🐛 Update packngo calls
2 parents f1ac0b9 + 6094ecb commit 0e32271

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ E2E_DIR ?= $(REPO_ROOT)/test/e2e
148148
KUBETEST_CONF_PATH ?= $(abspath $(E2E_DIR)/data/kubetest/conformance.yaml)
149149
E2E_CONF_FILE_SOURCE ?= $(E2E_DIR)/config/packet-ci.yaml
150150
E2E_CONF_FILE ?= $(E2E_DIR)/config/packet-ci-envsubst.yaml
151+
E2E_LD_FLAGS ?= "-X 'sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet.clientName=capp-e2e' -X 'sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet.clientUAFormat=capp-e2e/%s %s'"
151152

152153
.PHONY: $(E2E_CONF_FILE)
153154
$(E2E_CONF_FILE): $(ENVSUBST) $(E2E_CONF_FILE_SOURCE)
@@ -159,6 +160,7 @@ run-e2e-tests: $(KUBECTL) $(KUSTOMIZE) $(KIND) $(GINKGO) $(E2E_CONF_FILE) e2e-te
159160
$(MAKE) set-manifest-image MANIFEST_IMG=$(REGISTRY)/$(IMAGE_NAME) MANIFEST_TAG=$(TAG)
160161
$(MAKE) set-manifest-pull-policy PULL_POLICY=IfNotPresent
161162
cd test/e2e; time $(GINKGO) -v -trace -progress -v -tags=e2e \
163+
-ldflags $(E2E_LD_FLAGS) \
162164
--randomizeAllSpecs -race $(GINKGO_ADDITIONAL_ARGS) \
163165
-focus=$(GINKGO_FOCUS) -skip=$(GINKGO_SKIP) \
164166
-nodes=$(GINKGO_NODES) --noColor=$(GINKGO_NOCOLOR) \

pkg/cloud/packet/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ import (
3838

3939
const (
4040
apiTokenVarName = "PACKET_API_KEY" //nolint:gosec
41-
clientName = "CAPP-v1beta1"
42-
clientUAFormat = "cluster-api-provider-packet/%s %s"
4341
ipxeOS = "custom_ipxe"
4442
envVarLocalASN = "METAL_LOCAL_ASN"
4543
envVarBGPPass = "METAL_BGP_PASS" //nolint:gosec
4644
DefaultLocalASN = 65000
4745
)
4846

4947
var (
48+
clientName = "CAPP-v1beta1"
49+
clientUAFormat = "cluster-api-provider-packet/%s %s"
5050
ErrControlPlanEndpointNotFound = errors.New("control plane not found")
5151
ErrElasticIPQuotaExceeded = errors.New("could not create an Elastic IP due to quota limits on the account, please contact Equinix Metal support")
5252
ErrInvalidIP = errors.New("invalid IP")

test/e2e/common_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"k8s.io/client-go/tools/clientcmd"
4242
"k8s.io/client-go/tools/clientcmd/api"
4343
"sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"
44-
"sigs.k8s.io/cluster-api-provider-packet/version"
4544
clusterv1old "sigs.k8s.io/cluster-api/api/v1alpha3"
4645
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4746
"sigs.k8s.io/cluster-api/test/framework"
@@ -210,8 +209,7 @@ func (w *wrappedClusterProxy) Dispose(ctx context.Context) {
210209
metalAuthToken := os.Getenv(AuthTokenEnvVar)
211210
metalProjectID := os.Getenv(ProjectIDEnvVar)
212211
if metalAuthToken != "" && metalProjectID != "" {
213-
metal := packet.NewClientWithAuth(clientName, metalAuthToken)
214-
metal.UserAgent = fmt.Sprintf("capp-e2e/%s %s", version.Version, metalClient.UserAgent)
212+
metalClient := packet.NewClient(metalAuthToken)
215213

216214
Eventually(func(g Gomega) {
217215
clusterNames := w.clusterNames.UnsortedList()
@@ -222,7 +220,7 @@ func (w *wrappedClusterProxy) Dispose(ctx context.Context) {
222220

223221
g.Eventually(func(g Gomega) {
224222
var err error
225-
ip, err = metal.GetIPByClusterIdentifier("", clusterName, metalProjectID)
223+
ip, err = metalClient.GetIPByClusterIdentifier("", clusterName, metalProjectID)
226224
g.Expect(err).To(SatisfyAny(Not(HaveOccurred()), MatchError(packet.ErrControlPlanEndpointNotFound)))
227225
}, "5m", "10s").Should(Succeed())
228226

@@ -231,7 +229,7 @@ func (w *wrappedClusterProxy) Dispose(ctx context.Context) {
231229
logf("Deleting EIP with ID: %s, for cluster: %s", ip.ID, clusterName)
232230

233231
g.Eventually(func(g Gomega) {
234-
_, err := metal.ProjectIPs.Remove(ip.ID)
232+
_, err := metalClient.ProjectIPs.Remove(ip.ID)
235233
Expect(err).NotTo(HaveOccurred())
236234
}, "5m", "10s").Should(Succeed())
237235

test/e2e/suite_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import (
4444
"sigs.k8s.io/cluster-api/util"
4545

4646
"sigs.k8s.io/cluster-api-provider-packet/api/v1beta1"
47-
"sigs.k8s.io/cluster-api-provider-packet/version"
47+
"sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"
4848
)
4949

5050
const (
@@ -179,8 +179,7 @@ var _ = SynchronizedAfterSuite(func() {
179179
metalAuthToken := os.Getenv(AuthTokenEnvVar)
180180
if metalAuthToken != "" && sshKeyID != "" {
181181
By("Cleaning up the generated SSH Key")
182-
metalClient := packngo.NewClientWithAuth("capp-e2e", metalAuthToken, nil)
183-
metalClient.UserAgent = fmt.Sprintf("capp-e2e/%s %s", version.Version, metalClient.UserAgent)
182+
metalClient := packet.NewClient(metalAuthToken)
184183
_, err := metalClient.SSHKeys.Delete(sshKeyID)
185184
Expect(err).NotTo(HaveOccurred())
186185
}
@@ -288,8 +287,7 @@ func generateSSHKey() (string, string) {
288287
pub, err := ssh.NewPublicKey(&privateKey.PublicKey)
289288
Expect(err).NotTo(HaveOccurred())
290289

291-
metalClient := packngo.NewClientWithAuth("capp-e2e", metalAuthToken, nil)
292-
metalClient.UserAgent = fmt.Sprintf("capp-e2e/%s %s", version.Version, metalClient.UserAgent)
290+
metalClient := packet.NewClient(metalAuthToken)
293291
res, _, err := metalClient.SSHKeys.Create(
294292
&packngo.SSHKeyCreateRequest{
295293
Label: fmt.Sprintf("capp-e2e-%s", util.RandomString(6)),

version/version.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
)
2525

2626
var (
27-
gitMajor string // major version, always numeric
28-
gitMinor string // minor version, numeric possibly followed by "+"
29-
gitVersion string // semantic version, derived by build scripts
30-
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
31-
gitTreeState string // state of git tree, either "clean" or "dirty"
32-
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
27+
gitMajor string // major version, always numeric
28+
gitMinor string // minor version, numeric possibly followed by "+"
29+
gitVersion = "dev" // semantic version, derived by build scripts
30+
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
31+
gitTreeState string // state of git tree, either "clean" or "dirty"
32+
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
3333
)
3434

3535
// Info contains all version-related information.

0 commit comments

Comments
 (0)