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

Do not use "latest" GKE engine in examples. #343

Merged
merged 1 commit into from
Jul 10, 2019
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
Do not use "latest" GKE engine in examples.
Using a fuzzy version as an input to `nodeVersion` can cause spurious
diffs, as the state returned by the provider will contain a specific
version for this field. Instead, fetch the latest version from GKE using
`getEngineVersions` and use that.
  • Loading branch information
pgavlin committed Jul 10, 2019
commit 23898cb56140ce73a4279c7262d43f9201cc2ebb
8 changes: 5 additions & 3 deletions gcp-py-gke/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pulumi import Config, export, get_project, get_stack, Output, ResourceOptions
from pulumi_gcp.config import project, zone
from pulumi_gcp.container import Cluster
from pulumi_gcp.container import Cluster, get_engine_versions
from pulumi_kubernetes import Provider
from pulumi_kubernetes.apps.v1 import Deployment
from pulumi_kubernetes.core.v1 import Service
Expand All @@ -19,11 +19,13 @@
# password is the password for the admin user in the cluster.
PASSWORD = config.get_secret('password') or RandomString("password", length=20, special=True).result

engine_version = Output.from_input(get_engine_versions()).latest_master_version
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty "strange" looking code to have to add to the top of many of our intro-to-pulumi examples. I'd actually be inclined to just hard code a version and have to fix up our examples occasionally as these get updated - or pick this up from config and hard code the values into the test config?

I don't love hurting readability/usability of examples just to make testing easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd love to make this easier to read, but I do kind of prefer this approach to the hard-coded version approach. If I knew Python better, I would have avoided the Output.from_input bit.

That said, this is important content, so I'll defer to you if you feel strongly here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hard-coding into the config seems reasonable-ish, as we could also pull the latest version inside the test framework if we cared to.


# Now, actually create the GKE cluster.
k8s_cluster = Cluster('gke-cluster',
initial_node_count=NODE_COUNT,
node_version='latest',
min_master_version='latest',
node_version=engine_version,
min_master_version=engine_version,
master_auth={ 'username': USERNAME, 'password': PASSWORD },
node_config={
'machine_type': NODE_MACHINE_TYPE,
Expand Down
7 changes: 5 additions & 2 deletions gcp-ts-gke-hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as gcp from "@pulumi/gcp";

const name = "helloworld";

// Find the latest engine version.
const engineVersion = gcp.container.getEngineVersions().then(v => v.latestMasterVersion);

// Create a GKE cluster
const cluster = new gcp.container.Cluster(name, {
initialNodeCount: 2,
minMasterVersion: "latest",
nodeVersion: "latest",
minMasterVersion: engineVersion,
nodeVersion: engineVersion,
nodeConfig: {
machineType: "n1-standard-1",
oauthScopes: [
Expand Down
7 changes: 5 additions & 2 deletions gcp-ts-gke/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import { nodeCount, nodeMachineType, password, username } from "./config";

// Find the latest engine version.
const engineVersion = gcp.container.getEngineVersions().then(v => v.latestMasterVersion);

// Create the GKE cluster and export it.
export const k8sCluster = new gcp.container.Cluster("gke-cluster", {
initialNodeCount: nodeCount,
nodeVersion: "latest",
minMasterVersion: "latest",
nodeVersion: engineVersion,
minMasterVersion: engineVersion,
masterAuth: { username, password },
nodeConfig: {
machineType: nodeMachineType,
Expand Down
7 changes: 5 additions & 2 deletions gcp-ts-k8s-ruby-on-rails-postgresql/infra/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import { clusterNodeCount, clusterNodeMachineType, clusterPassword, clusterUsername } from "./config";

// Find the latest engine version.
const engineVersion = gcp.container.getEngineVersions().then(v => v.latestMasterVersion);

// Create the GKE cluster and export it.
export const cluster = new gcp.container.Cluster("gke-cluster", {
initialNodeCount: clusterNodeCount,
nodeVersion: "latest",
minMasterVersion: "latest",
nodeVersion: engineVersion,
minMasterVersion: engineVersion,
masterAuth: { username: clusterUsername, password: clusterPassword },
nodeConfig: {
machineType: clusterNodeMachineType,
Expand Down