Skip to content

Commit

Permalink
Merge pull request #14778 from justinsb/gcs_oidc_just_context
Browse files Browse the repository at this point in the history
Introduce context.Context into some of our "Context" objects
  • Loading branch information
k8s-ci-robot authored Dec 13, 2022
2 parents d628681 + 5fde739 commit 091754f
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 50 deletions.
5 changes: 4 additions & 1 deletion nodeup/pkg/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package bootstrap

import (
"context"
"fmt"
"os"
"strings"
Expand All @@ -37,6 +38,8 @@ type Installation struct {
}

func (i *Installation) Run() error {
ctx := context.TODO()

_, err := distributions.FindDistribution("/")
if err != nil {
return fmt.Errorf("error determining OS distribution: %v", err)
Expand Down Expand Up @@ -72,7 +75,7 @@ func (i *Installation) Run() error {
}

checkExisting := true
context, err := fi.NewContext(target, nil, cloud, keyStore, secretStore, configBase, checkExisting, tasks)
context, err := fi.NewContext(ctx, target, nil, cloud, keyStore, secretStore, configBase, checkExisting, tasks)
if err != nil {
return fmt.Errorf("error building context: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testutils/integrationtestharness.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type IntegrationTestHarness struct {

func NewIntegrationTestHarness(t *testing.T) *IntegrationTestHarness {
featureflag.ParseFlags("-ImageDigest")
h := &IntegrationTestHarness{}
h := &IntegrationTestHarness{T: t}
tempDir, err := os.MkdirTemp("", "test")
if err != nil {
t.Fatalf("failed to create temp dir: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
return fmt.Errorf("unknown cloudprovider %q", cluster.Spec.GetCloudProvider())
}
}
c.TaskMap, err = l.BuildTasks(c.LifecycleOverrides)
c.TaskMap, err = l.BuildTasks(ctx, c.LifecycleOverrides)
if err != nil {
return fmt.Errorf("error building tasks: %v", err)
}
Expand Down Expand Up @@ -783,7 +783,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
}
}

context, err := fi.NewContext(target, cluster, cloud, keyStore, secretStore, configBase, checkExisting, c.TaskMap)
context, err := fi.NewContext(ctx, target, cluster, cloud, keyStore, secretStore, configBase, checkExisting, c.TaskMap)
if err != nil {
return fmt.Errorf("error building context: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package awstasks

import (
"context"
"reflect"
"testing"

Expand All @@ -28,6 +29,8 @@ import (
)

func TestSharedEgressOnlyInternetGatewayDoesNotRename(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -95,7 +98,7 @@ func TestSharedEgressOnlyInternetGatewayDoesNotRename(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -139,6 +142,6 @@ func TestSharedEgressOnlyInternetGatewayDoesNotRename(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}
11 changes: 7 additions & 4 deletions upup/pkg/fi/cloudup/awstasks/elastic_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package awstasks

import (
"bytes"
"context"
"os"
"reflect"
"testing"
Expand All @@ -38,6 +39,8 @@ var testRunTasksOptions = fi.RunTasksOptions{
}

func TestElasticIPCreate(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -78,7 +81,7 @@ func TestElasticIPCreate(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -115,19 +118,19 @@ func TestElasticIPCreate(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}

func checkNoChanges(t *testing.T, cloud fi.Cloud, allTasks map[string]fi.Task) {
func checkNoChanges(t *testing.T, ctx context.Context, cloud fi.Cloud, allTasks map[string]fi.Task) {
cluster := &kops.Cluster{
Spec: kops.ClusterSpec{
KubernetesVersion: "v1.9.0",
},
}
assetBuilder := assets.NewAssetBuilder(cluster, false)
target := fi.NewDryRunTarget(assetBuilder, os.Stderr)
context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down
7 changes: 5 additions & 2 deletions upup/pkg/fi/cloudup/awstasks/internetgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package awstasks

import (
"context"
"reflect"
"testing"

Expand All @@ -28,6 +29,8 @@ import (
)

func TestSharedInternetGatewayDoesNotRename(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -111,7 +114,7 @@ func TestSharedInternetGatewayDoesNotRename(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -155,6 +158,6 @@ func TestSharedInternetGatewayDoesNotRename(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}
7 changes: 5 additions & 2 deletions upup/pkg/fi/cloudup/awstasks/securitygroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package awstasks

import (
"context"
"reflect"
"testing"

Expand Down Expand Up @@ -94,6 +95,8 @@ func testNotMatches(t *testing.T, rule *PortRemovalRule, permission *ec2.Securit
}

func TestSecurityGroupCreate(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -129,7 +132,7 @@ func TestSecurityGroupCreate(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -167,6 +170,6 @@ func TestSecurityGroupCreate(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}
25 changes: 17 additions & 8 deletions upup/pkg/fi/cloudup/awstasks/subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package awstasks

import (
"context"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -64,6 +65,8 @@ func Test_Subnet_CannotChangeSubnet(t *testing.T) {
}

func TestSubnetCreate(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -99,7 +102,7 @@ func TestSubnetCreate(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -142,11 +145,13 @@ func TestSubnetCreate(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}

func TestSubnetCreateIPv6(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -190,7 +195,7 @@ func TestSubnetCreateIPv6(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -242,11 +247,13 @@ func TestSubnetCreateIPv6(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}

func TestSubnetCreateIPv6NetNum(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -289,7 +296,7 @@ func TestSubnetCreateIPv6NetNum(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -341,11 +348,13 @@ func TestSubnetCreateIPv6NetNum(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}

func TestSharedSubnetCreateDoesNotCreateNew(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand Down Expand Up @@ -422,7 +431,7 @@ func TestSharedSubnetCreateDoesNotCreateNew(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -470,6 +479,6 @@ func TestSharedSubnetCreateDoesNotCreateNew(t *testing.T) {

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}
11 changes: 8 additions & 3 deletions upup/pkg/fi/cloudup/awstasks/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package awstasks

import (
"context"
"reflect"
"testing"

Expand All @@ -28,6 +29,8 @@ import (
)

func TestVPCCreate(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
cloud.MockEC2 = c
Expand All @@ -53,7 +56,7 @@ func TestVPCCreate(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down Expand Up @@ -91,7 +94,7 @@ func TestVPCCreate(t *testing.T) {
{
allTasks := buildTasks()

checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}

Expand Down Expand Up @@ -132,6 +135,8 @@ func Test4758(t *testing.T) {
}

func TestSharedVPCAdditionalCIDR(t *testing.T) {
ctx := context.TODO()

cloud := awsup.BuildMockAWSCloud("us-east-1", "abc")
c := &mockec2.MockEC2{}
c.CreateVpcWithId(&ec2.CreateVpcInput{
Expand Down Expand Up @@ -177,7 +182,7 @@ func TestSharedVPCAdditionalCIDR(t *testing.T) {
Cloud: cloud,
}

context, err := fi.NewContext(target, nil, cloud, nil, nil, nil, true, allTasks)
context, err := fi.NewContext(ctx, target, nil, cloud, nil, nil, nil, true, allTasks)
if err != nil {
t.Fatalf("error building context: %v", err)
}
Expand Down
9 changes: 6 additions & 3 deletions upup/pkg/fi/cloudup/gcetasks/projectiambinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ limitations under the License.
package gcetasks

import (
"context"
"testing"

gcemock "k8s.io/kops/cloudmock/gce"
"k8s.io/kops/upup/pkg/fi"
)

func TestProjectIAMBinding(t *testing.T) {
ctx := context.TODO()

project := "testproject"
region := "us-test1"

Expand All @@ -46,16 +49,16 @@ func TestProjectIAMBinding(t *testing.T) {

{
allTasks := buildTasks()
checkHasChanges(t, cloud, allTasks)
checkHasChanges(t, ctx, cloud, allTasks)
}

{
allTasks := buildTasks()
runTasks(t, cloud, allTasks)
runTasks(t, ctx, cloud, allTasks)
}

{
allTasks := buildTasks()
checkNoChanges(t, cloud, allTasks)
checkNoChanges(t, ctx, cloud, allTasks)
}
}
Loading

0 comments on commit 091754f

Please sign in to comment.