Skip to content

Commit

Permalink
Automated Config Connector import.
Browse files Browse the repository at this point in the history
  - 2b4f8d759b42a17891f055edc4be9bab3198325d Fix dataflow flex fix for experimental handling. by Config Connector Team <[email protected]>

GitOrigin-RevId: 2b4f8d759b42a17891f055edc4be9bab3198325d
  • Loading branch information
Config Connector Team authored and copybara-github committed Jul 11, 2023
1 parent a87ba38 commit 6dbdd94
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions hack/terraform-overrides/dataflow_flex_template_job.patch
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ diff --git a/third_party/github.com/hashicorp/terraform-provider-google-beta/goo
index 42765a1eb..4a8d9f94f 100644
--- a/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/resource_dataflow_flex_template_job.go
+++ b/third_party/github.com/hashicorp/terraform-provider-google-beta/google-beta/resource_dataflow_flex_template_job.go
@@ -362,6 +362,9 @@ func resourceDataflowFlexTemplateJobRead(d *schema.ResourceData, meta interface{
if err := d.Set("network", optionsMap["network"]); err != nil {
return fmt.Errorf("Error setting network: %s", err)
}
+ if err := d.Set("additional_experiments", optionsMap["experiments"]); err != nil {
+ return fmt.Errorf("Error setting additional_experiments: %s", err)
+ }
if err := d.Set("num_workers", optionsMap["numWorkers"]); err != nil {
return fmt.Errorf("Error setting num_workers: %s", err)
}
@@ -382,12 +382,6 @@ func resourceDataflowFlexTemplateJobRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("Error setting machine_type: %s", err)
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/controller/dynamic/dynamic_controller_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"context"
"flag"
"fmt"
"net/http"
"os"
"path/filepath"
"reflect"
"regexp"
"strings"
Expand All @@ -35,6 +38,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/servicemapping/servicemappingloader"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
testcontroller "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/controller"
testreconciler "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/controller/reconciler"
testgcp "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/gcp"
Expand All @@ -47,12 +51,19 @@ import (

"github.com/cenkalti/backoff"
"github.com/ghodss/yaml"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

type httpRoundTripperKeyType int

// httpRoundTripperKey is the key value for http.RoundTripper in a context.Context
var httpRoundTripperKey httpRoundTripperKeyType

func init() {
// run-tests and skip-tests allows you to limit the tests that are run by
// specifying regexes to be used to match test names. See the
Expand All @@ -66,6 +77,23 @@ func init() {
// To use this flag, you MUST use an equals sign as follows: go test -tags=integration -cleanup-resources=false
flag.BoolVar(&cleanupResources, "cleanup-resources", true, "when enabled, "+
"cloud resources created by tests will be cleaned up at the end of a test")

// Allow for capture of http requests during a test.
transport_tpg.DefaultHTTPClientTransformer = func(ctx context.Context, inner *http.Client) *http.Client {
ret := inner
if t := ctx.Value(httpRoundTripperKey); t != nil {
ret = &http.Client{Transport: t.(http.RoundTripper)}
}
if artifacts := os.Getenv("ARTIFACTS"); artifacts == "" {
log := log.FromContext(ctx)
log.Info("env var ARTIFACTS is not set; will not record http log")
} else {
outputDir := filepath.Join(artifacts, "http-logs")
t := test.NewHTTPRecorder(ret.Transport, outputDir)
ret = &http.Client{Transport: t}
}
return ret
}
}

var (
Expand Down Expand Up @@ -188,6 +216,7 @@ func testCreate(t *testing.T, testContext testrunner.TestContext, systemContext
if err := kubeClient.Create(context.TODO(), initialUnstruct); err != nil {
t.Fatalf("error creating %v resource %v: %v", initialUnstruct.GetKind(), initialUnstruct.GetName(), err)
}
t.Logf("resource created with %v\r", initialUnstruct)
systemContext.Reconciler.Reconcile(initialUnstruct, testreconciler.ExpectedSuccessfulReconcileResultFor(systemContext.Reconciler, initialUnstruct), nil)
validateCreate(t, testContext, systemContext, resourceContext, initialUnstruct.GetGeneration())
}
Expand All @@ -210,6 +239,7 @@ func validateCreate(t *testing.T, testContext testrunner.TestContext, systemCont
if err != nil {
t.Fatalf("unexpected error when GETting '%v': %v", initialUnstruct.GetName(), err)
}
t.Logf("created resource is %v\r", gcpUnstruct)
if resourceContext.SupportsLabels(systemContext.SMLoader) {
testcontroller.AssertLabelsMatchAndHaveManagedLabel(t, gcpUnstruct.GetLabels(), reconciledUnstruct.GetLabels())
}
Expand Down Expand Up @@ -312,6 +342,7 @@ func testUpdate(t *testing.T, testContext testrunner.TestContext, systemContext
t.Fatalf("error setting status on updateUnstruct: %v", err)
}
patch := client.MergeFrom(testContext.CreateUnstruct)
t.Logf("patching %v with %v\r", updateUnstruct, patch)
if err := kubeClient.Patch(context.TODO(), updateUnstruct, patch); err != nil {
t.Fatalf("unexpected error when updating '%v': %v", initialUnstruct.GetName(), err)
}
Expand Down Expand Up @@ -394,7 +425,9 @@ func testDriftCorrection(t *testing.T, testContext testrunner.TestContext, syste
time.Sleep(time.Second * 10)

// get the current state
t.Logf("reconcile with %v\r", testUnstruct)
systemContext.Reconciler.Reconcile(testUnstruct, testreconciler.ExpectedSuccessfulReconcileResultFor(systemContext.Reconciler, testUnstruct), nil)
t.Logf("reconciled with %v\r", testUnstruct)
validateCreate(t, testContext, systemContext, resourceContext, testUnstruct.GetGeneration())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ spec:
inputSubscription: projects/${projectId}/subscriptions/pubsubsubscription-${uniqueId}
outputTopic: projects/${projectId}/topics/pubsubtopic1-${uniqueId}
outputTableSpec: ${projectId}:bigquerydataset${uniqueId}.bigquerytable${uniqueId}
createDisposition: CREATE_NEVER
createDisposition: CREATE_NEVER
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ func resourceDataflowFlexTemplateJobRead(d *schema.ResourceData, meta interface{
if err := d.Set("network", optionsMap["network"]); err != nil {
return fmt.Errorf("Error setting network: %s", err)
}
if err := d.Set("additional_experiments", optionsMap["experiments"]); err != nil {
return fmt.Errorf("Error setting additional_experiments: %s", err)
}
if err := d.Set("num_workers", optionsMap["numWorkers"]); err != nil {
return fmt.Errorf("Error setting num_workers: %s", err)
}
Expand Down

0 comments on commit 6dbdd94

Please sign in to comment.