Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Go Azure examples to fnOutput form #1154

Merged
merged 11 commits into from
Jan 21, 2022

Conversation

dixler
Copy link
Contributor

@dixler dixler commented Jan 21, 2022

#1115

examples/azure-go-containerapps
attempted bumping azure-native, but ran into an issue another user ran into. It was due to an upstream dependency on azure. Omitting changes.

@@ -30,7 +30,7 @@ func configure(ctx *pulumi.Context) (Config, error) {

out.K8sVersion = cfg.Get("k8sVersion")
if out.K8sVersion == "" {
out.K8sVersion = "1.18.14"
Copy link
Contributor Author

@dixler dixler Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This k8s version was no longer supported.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@@ -54,11 +54,6 @@ func buildCluster(ctx *pulumi.Context, cfg Config) (*ClusterInfo, error) {
k8sCluster, err := cs.NewManagedCluster(ctx, "cluster",
&cs.ManagedClusterArgs{
ResourceGroupName: resourceGroup.Name,
AddonProfiles: cs.ManagedClusterAddonProfileMap{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The k8s version bump broke compatibility with this addon so I removed it. It didn't appear to be a significant part of the README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@@ -13,6 +13,27 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func getKubeconfig(ctx *pulumi.Context, cluster *containerservice.ManagedCluster, resourceGroup *resources.ResourceGroup) pulumi.Output {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broke this out into a separate function to break apart the instantiation logic and the kubeconfig logic.

@@ -48,9 +48,33 @@ The example shows two scenarios:

```
$ pulumi stack output helloEndpoint
http:https://hello-app-91dfea.azurewebsites.net/hello
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the image to an image that exists so I updated the README with the expected outputs.

//
imageInDockerHub := "microsoft/azure-appservices-go-quickstart"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this image was 404'ing

I replaced it with an nginx base image since it's about deploying an image from docker hub

@@ -57,7 +57,7 @@ func main() {
}

ctx.Export("helloEndpoint", helloApp.DefaultHostName.ApplyT(func(defaultHostName string) (string, error) {
return fmt.Sprintf("%v%v%v", "https://", defaultHostName, "/hello"), nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nginx image doesn't have a /hello route

@@ -44,7 +44,7 @@ func main() {
}
_, err = authorization.NewRoleAssignment(ctx, "access-from-cluster", &authorization.RoleAssignmentArgs{
PrincipalId: pulumi.String(currentPrincipal),
PrincipalType: authorization.PrincipalTypeUser, // adjust the type if you are running as a service principal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped the version and this line threw an error.

@@ -22,7 +22,7 @@ func main() {
profile, err := cdn.NewProfile(ctx, "profile", &cdn.ProfileArgs{
ResourceGroupName: resourceGroup.Name,
Sku: &cdn.SkuArgs{
Name: cdn.SkuName_Standard_Microsoft,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped the version and this line threw an error.

@dixler dixler marked this pull request as ready for review January 21, 2022 16:09
}
return *ip.Ip, nil
}).(pulumi.StringOutput))
ctx.Export("containerIPv4Address", containerGroup.IpAddress.Ip())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ApplyT used to coerce *string to string by interpreting nil as "". IS that still happening? Does ctx.Export work with nils? Have you had a chance to test this? The CI does not test all examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kdixler@kdixler-20xw004aus ~/GolandProjects/examples/azure-go-aci (git)-[dixler/1115/refactor-azure-go-binless] % pulumi up
Previewing update (issue1115)

View Live: https://app.pulumi.com/kyle/azure-go-aci/issue1115/previews/c49fb6bf-3e9c-4581-b200-56878bd789e1

     Type                                              Name                    Plan       
 +   pulumi:pulumi:Stack                               azure-go-aci-issue1115  create     
 +   ├─ azure-native:resources:ResourceGroup           aci-rg                  create     
 +   └─ azure-native:containerinstance:ContainerGroup  helloworld              create     
 
Resources:
    + 3 to create

Do you want to perform this update? yes
Updating (issue1115)

View Live: https://app.pulumi.com/kyle/azure-go-aci/issue1115/updates/6

     Type                                              Name                    Status      
 +   pulumi:pulumi:Stack                               azure-go-aci-issue1115  created     
 +   ├─ azure-native:resources:ResourceGroup           aci-rg                  created     
 +   └─ azure-native:containerinstance:ContainerGroup  helloworld              created     
 
Outputs:
    containerIPv4Address: "20.120.145.148"

Resources:
    + 3 created

Duration: 1m11s

kubeconfig := pulumi.All(cluster.Name, resourceGroup.Name, resourceGroup.ID()).ApplyT(func(args interface{}) (string, error) {
clusterName := args.([]interface{})[0].(string)
resourceGroupName := args.([]interface{})[1].(string)
creds, err := containerservice.ListManagedClusterUserCredentials(ctx, &containerservice.ListManagedClusterUserCredentialsArgs{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there now a ListManagedClusterUserCredentialsOutput function?

The idea is that the code may be simplified if you use that since it would let you avoid pulumi.All plus unpacking of args. You would pass cluster.Name etc directly to that function.

})
},
)
credentials := containerregistry.ListRegistryCredentialsOutput(ctx, containerregistry.ListRegistryCredentialsOutputArgs{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, had a few comments. Are these all examples that can use Output forms? I vaguely remember a few more but I don't have a list handy. Let me check my notes.

@t0yv0
Copy link
Member

t0yv0 commented Jan 21, 2022

Mini list in #1094 - if you haven't looked at those yet it'd be good to double-check

The following examples cannot update yet because pulumi-azure-native Go SDK opts out of the feature via a flag:

azure-go-aks
azure-go-aks-helm
azure-go-appservice-docker
They do look like they would benefit.

@@ -98,25 +93,21 @@ func buildCluster(ctx *pulumi.Context, cfg Config) (*ClusterInfo, error) {
}

func getKubeconfig(ctx *pulumi.Context, cluster *ClusterInfo) pulumi.StringOutput {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found and refactored this function as well @t0yv0

@dixler dixler requested a review from t0yv0 January 21, 2022 19:36

kubeconfig := creds.Kubeconfigs().Index(pulumi.Int(0)).Value().
ApplyT(func(encoded string) string {
kubeconfig, err := base64.StdEncoding.DecodeString(encoded)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good I'm just paranoid about go runtime errors , sometimes Go compiles but throws a runtime error; running this would be invaluable (unless it's included in CI).

@t0yv0
Copy link
Member

t0yv0 commented Jan 21, 2022

Still LGTM.

@t0yv0
Copy link
Member

t0yv0 commented Jan 21, 2022

Is CI failure related to the changes? CI here is sometimes a little flaky.

@dixler
Copy link
Contributor Author

dixler commented Jan 21, 2022

Is CI failure related to the changes? CI here is sometimes a little flaky.

/home/runner/work/examples/examples/classic-azure-ts-stream-analytics
seems to be a different example than the ones I worked on.

@dixler dixler merged commit 04e4a18 into master Jan 21, 2022
@pulumi-bot pulumi-bot deleted the dixler/1115/refactor-azure-go-binless branch January 21, 2022 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants