Skip to content

Commit

Permalink
Update go sdk references
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
  • Loading branch information
jsturtevant committed Jul 16, 2024
1 parent 20ea05f commit f90557f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 75 deletions.
35 changes: 11 additions & 24 deletions capz/gmsa/configuration/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
"github.com/Azure/azure-sdk-for-go/profiles/latest/network/mgmt/network"
"github.com/Azure/azure-sdk-for-go/services/keyvault/v7.0/keyvault"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets"
. "github.com/onsi/gomega" //nolint:revive
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -83,33 +81,22 @@ func getKubeConfigPath() string {
}

func configureGmsa(ctx context.Context, bootstrapClusterProxy framework.ClusterProxy, namespace, clusterName string) {
settings, err := auth.GetSettingsFromEnvironment()
cred, err := azidentity.NewDefaultAzureCredential(nil)
Expect(err).NotTo(HaveOccurred())
authorizer, err := settings.GetAuthorizer()
Expect(err).NotTo(HaveOccurred())
subID := settings.GetSubscriptionID()

Expect(err).NotTo(HaveOccurred())
keyVaultClient := keyvault.New()

vmClient := compute.NewVirtualMachinesClient(subID)
vmClient.Authorizer = authorizer

networkClient := network.NewVirtualNetworkPeeringsClient(subID)
networkClient.Authorizer = authorizer

keyvaultAuthorizer, err := settings.GetAuthorizer()
keyVaultClient, err := azsecrets.NewClient(os.Getenv("GMSA_KEYVAULT_URL"), cred, nil)
Expect(err).NotTo(HaveOccurred())
keyVaultClient.Authorizer = keyvaultAuthorizer

workloadProxy := bootstrapClusterProxy.GetWorkloadCluster(ctx, namespace, clusterName)

// Wait for the Domain to finish provisioning. The existence of the spec file is the marker
gmsaSpecName := "gmsa-cred-spec-gmsa-e2e-" + os.Getenv("GMSA_ID")
fmt.Printf("INFO: Getting the gmsa gmsaSpecFile %s from %s\n", gmsaSpecName, os.Getenv("GMSA_KEYVAULT_URL"))
var gmsaSpecFile keyvault.SecretBundle
var gmsaSpecFile azsecrets.GetSecretResponse
Eventually(func() error {
gmsaSpecFile, err = keyVaultClient.GetSecret(ctx, os.Getenv("GMSA_KEYVAULT_URL"), gmsaSpecName, "")
// empty string for version gets the latest
version := ""
gmsaSpecFile, err = keyVaultClient.GetSecret(ctx, gmsaSpecName, version, nil)
if capz.ResourceNotFound(err) {
fmt.Printf("INFO: Waiting for gmsaSpecFile %s to be created by Domain controller\n", os.Getenv("GMSA_KEYVAULT_URL"))
return err
Expand All @@ -128,7 +115,7 @@ func configureGmsa(ctx context.Context, bootstrapClusterProxy framework.ClusterP
clusterHostName := workloadCluster.Spec.ControlPlaneEndpoint.Host

gmsaNode, windowsNodes := labelGmsaTestNode(ctx, workloadProxy)
dropGmsaSpecOnTestNode(gmsaNode, clusterHostName, gmsaSpecFile)
dropGmsaSpecOnTestNode(gmsaNode, clusterHostName, gmsaSpecFile.Value)
configureCoreDNS(ctx, workloadProxy)

for _, n := range windowsNodes.Items {
Expand Down Expand Up @@ -183,14 +170,14 @@ func configureCoreDNS(ctx context.Context, workloadProxy framework.ClusterProxy)
Expect(err).NotTo(HaveOccurred())
}

func dropGmsaSpecOnTestNode(gmsaNode *corev1.Node, clusterHostName string, secret keyvault.SecretBundle) {
func dropGmsaSpecOnTestNode(gmsaNode *corev1.Node, clusterHostName string, value *string) {
fmt.Printf("INFO: Writing gmsa spec to disk\n")
f, err := fileOnHost(filepath.Join("", "gmsa-spec-writer-output.txt"))
Expect(err).NotTo(HaveOccurred())
defer f.Close()
hostname := getHostName(gmsaNode)

cmd := fmt.Sprintf("mkdir -force /gmsa; rm -force c:/gmsa/gmsa-cred-spec-gmsa-e2e.yml; $input='%s'; [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($input)) >> c:/gmsa/gmsa-cred-spec-gmsa-e2e.yml", *secret.Value)
cmd := fmt.Sprintf("mkdir -force /gmsa; rm -force c:/gmsa/gmsa-cred-spec-gmsa-e2e.yml; $input='%s'; [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($input)) >> c:/gmsa/gmsa-cred-spec-gmsa-e2e.yml", value)

Check failure on line 180 in capz/gmsa/configuration/configure.go

View workflow job for this annotation

GitHub Actions / lint go

printf: fmt.Sprintf format %s has arg value of wrong type *string (govet)
err = execOnHost(clusterHostName, hostname, "22", f, cmd)
Expect(err).NotTo(HaveOccurred())
}
Expand Down
39 changes: 21 additions & 18 deletions capz/gmsa/configuration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ module github.com/kubernetes-sigs/windows-testing/capz/gmsa/configuration
go 1.22

require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.1.0
github.com/onsi/gomega v1.27.6
github.com/pkg/errors v0.9.1
golang.org/x/crypto v0.11.0
golang.org/x/crypto v0.24.0
k8s.io/api v0.26.7
k8s.io/apimachinery v0.26.7
k8s.io/client-go v0.26.7
Expand All @@ -21,20 +20,23 @@ require (
require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230106234847-43070de90fa1 // indirect
github.com/Azure/aad-pod-identity v1.8.15 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.5.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.29 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.22 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/mocks v0.4.2 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
Expand Down Expand Up @@ -84,20 +86,21 @@ require (
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/cel-go v0.12.6 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v48 v48.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
Expand Down Expand Up @@ -145,7 +148,7 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pkg/sftp v1.13.5 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand All @@ -172,15 +175,15 @@ require (
go.opentelemetry.io/otel v1.15.1 // indirect
go.opentelemetry.io/otel/trace v1.15.1 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
Expand Down
Loading

0 comments on commit f90557f

Please sign in to comment.