Skip to content
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
8 changes: 5 additions & 3 deletions api/agent_token_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
"time"
)

// This is a special agent client: it can only be used to query the GET /token API.
// Meaning for this client to function, there isn't a need for a cluster id nor queue id.
// NewAgentTokenClient creates a new AgentTokenClient.
func NewAgentTokenClient(token, endpoint string) (*AgentTokenClient, error) {
if endpoint == "" {
endpoint = "https://agent.buildkite.com/v3"
Expand All @@ -26,6 +25,9 @@ func NewAgentTokenClient(token, endpoint string) (*AgentTokenClient, error) {
}, nil
}

// AgentTokenClient is a special Agent API client: it can only be used to query
// the GET /token API.
// This client doesn't need a cluster ID or queue ID in advance.
type AgentTokenClient struct {
endpoint *url.URL
httpClient *http.Client
Expand All @@ -44,7 +46,7 @@ type AgentTokenIdentity struct {
OrganizationQueueKey string `json:"organization_queue_key"`
}

// GetJobState gets the state of a specific job.
// GetTokenIdentity gets the identity information of an agent token.
func (c *AgentTokenClient) GetTokenIdentity(ctx context.Context) (result *AgentTokenIdentity, retryAfter time.Duration, err error) {
u := c.endpoint.JoinPath("token")

Expand Down
2 changes: 0 additions & 2 deletions internal/integration/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ func TestCleanupOrphanedPipelines(t *testing.T) {
var wg sync.WaitGroup
wg.Add(numPipelines)
for _, pipeline := range pipelines.Organization.Pipelines.Edges {
pipeline := pipeline // prevent loop variable capture

tc := testcase{
T: t,
GraphQL: api.NewGraphQLClient(cfg.BuildkiteToken, cfg.GraphQLEndpoint),
Expand Down
37 changes: 4 additions & 33 deletions internal/integration/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"
restconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
)

Expand Down Expand Up @@ -183,7 +184,7 @@ func (t testcase) createPipelineWithCleanup(ctx context.Context, queueName strin
Name: t.PipelineName,
Repository: t.Repo,
ProviderSettings: &buildkite.GitHubSettings{
TriggerMode: strPtr("none"),
TriggerMode: ptr.To("none"),
},
Configuration: steps.String(),
ClusterID: t.ClusterUUID,
Expand Down Expand Up @@ -417,30 +418,6 @@ func (t testcase) waitForBuild(ctx context.Context, build api.Build) api.BuildSt
}
}

func (t testcase) AssertMetadata(ctx context.Context, annotations, labelz map[string]string) {
t.Helper()

tagReq, err := labels.NewRequirement("tag.buildkite.com/queue", selection.Equals, []string{t.QueueName()})
require.NoError(t, err)

selector := labels.NewSelector().Add(*tagReq)

jobs, err := t.Kubernetes.BatchV1().
Jobs(cfg.Namespace).
List(ctx, v1.ListOptions{LabelSelector: selector.String()})
require.NoError(t, err)
require.Len(t, jobs.Items, 1)

for k, v := range annotations {
assert.Equal(t, jobs.Items[0].Annotations[k], v)
assert.Equal(t, jobs.Items[0].Spec.Template.Annotations[k], v)
}
for k, v := range labelz {
assert.Equal(t, jobs.Items[0].Labels[k], v)
assert.Equal(t, jobs.Items[0].Spec.Template.Labels[k], v)
}
}

func (t testcase) AssertHostAlias(ctx context.Context, alias string, host string) {
t.Helper()

Expand All @@ -457,21 +434,15 @@ func (t testcase) AssertHostAlias(ctx context.Context, alias string, host string

for _, hostAlias := range jobs.Items[0].Spec.Template.Spec.HostAliases {
if hostAlias.IP == host {
for _, actualAlias := range hostAlias.Hostnames {
if actualAlias == alias {
return
}
if slices.Contains(hostAlias.Hostnames, alias) {
return
}
}
}

assert.Fail(t, "host alias not found")
}

func strPtr(p string) *string {
return &p
}

func ignorableError(err error) bool {
reasons := []string{
"already finished",
Expand Down