Skip to content

Commit

Permalink
Fix prometheus-operator test to wait for the CRD to be ready before u…
Browse files Browse the repository at this point in the history
…se (#1172)
  • Loading branch information
metral committed Jun 22, 2020
1 parent 7c4a21b commit 4c10d59
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 135 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## HEAD (Unreleased)

### Improvements

- Fix prometheus-operator test to wait for the CRD to be ready before use (https://github.com/pulumi/pulumi-kubernetes/pull/1172)

## 2.3.1 (June 17, 2020)

### Improvements
Expand Down
57 changes: 28 additions & 29 deletions tests/examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,35 +188,34 @@ func TestAccHelmLocal(t *testing.T) {
integration.ProgramTest(t, &test)
}

// TODO: uncomment once https://github.com/pulumi/pulumi-kubernetes/issues/1137 is fixed.
//func TestAccPrometheusOperator(t *testing.T) {
// skipIfShort(t)
// test := getBaseOptions(t).
// With(integration.ProgramTestOptions{
// Dir: path.Join(getCwd(t), "prometheus-operator"),
// SkipRefresh: true,
// ExtraRuntimeValidation: func(
// t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
// ) {
// assert.NotNil(t, stackInfo.Deployment)
// assert.Equal(t, 10, len(stackInfo.Deployment.Resources))
// },
// EditDirs: []integration.EditDir{
// {
// Dir: path.Join(getCwd(t), "prometheus-operator", "steps"),
// Additive: true,
// ExtraRuntimeValidation: func(
// t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
// ) {
// assert.NotNil(t, stackInfo.Deployment)
// assert.Equal(t, 10, len(stackInfo.Deployment.Resources))
// },
// },
// },
// })
//
// integration.ProgramTest(t, &test)
//}
func TestAccPrometheusOperator(t *testing.T) {
skipIfShort(t)
test := getBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: path.Join(getCwd(t), "prometheus-operator"),
SkipRefresh: true,
ExtraRuntimeValidation: func(
t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 10, len(stackInfo.Deployment.Resources))
},
EditDirs: []integration.EditDir{
{
Dir: path.Join(getCwd(t), "prometheus-operator", "steps"),
Additive: true,
ExtraRuntimeValidation: func(
t *testing.T, stackInfo integration.RuntimeValidationStackInfo,
) {
assert.NotNil(t, stackInfo.Deployment)
assert.Equal(t, 10, len(stackInfo.Deployment.Resources))
},
},
},
})

integration.ProgramTest(t, &test)
}

func TestAccMariadb(t *testing.T) {
skipIfShort(t)
Expand Down
97 changes: 44 additions & 53 deletions tests/examples/prometheus-operator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,66 @@ import * as pulumi from "@pulumi/pulumi";
// PrometheusOperatorArgs are the options to configure on the CoreOS
// PrometheusOperator.
interface PrometheusOperatorArgs {
namespace: pulumi.Input<string>;
version?: string;
}

// PrometheusOperator implements the CoreOS Prometheus Operator.
export class PrometheusOperator extends pulumi.ComponentResource {
class PrometheusOperator extends pulumi.ComponentResource {
public readonly configFile: k8s.yaml.ConfigFile;
public readonly service: pulumi.Output<k8s.core.v1.Service>;
constructor(
name: string,
args: PrometheusOperatorArgs,
opts?: pulumi.ComponentResourceOptions,
) {
super('pulumi:monitoring/v1:PrometheusOperator', name, {}, opts);

this.configFile = new k8s.yaml.ConfigFile(
name,
{
file: `https://github.com/coreos/prometheus-operator/raw/release-${args.version || '0.38'}/bundle.yaml`,
transformations: [
obj => {
if (obj.metadata.namespace) {
obj.metadata.namespace = args.namespace;
}
if (obj.kind === 'ClusterRoleBinding') {
obj.subjects[0].namespace = args.namespace;
}
},
],
}, { parent: this });
this.configFile = new k8s.yaml.ConfigFile(name, {
file: `https://github.com/coreos/prometheus-operator/raw/release-${args.version || '0.38'}/bundle.yaml`,
}, {parent: this});

this.service = this.configFile.getResource("v1/Service", "default", "prometheus-operator");
}
}

// Create the Prometheus Operator.
const prometheusOperator = new PrometheusOperator("prometheus", {
namespace: "default",
});
const prometheusOperator = new PrometheusOperator("prometheus", {});

// Create the Prometheus Operator ServiceMonitor.
const myMonitoring = new k8s.apiextensions.CustomResource('my-monitoring', {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
spec: {
selector: {
matchLabels: { app: 'my-app' },
},
endpoints: [
{
port: 'http',
interval: '65s',
// start with the following
relabelings: [
{
regex: '(.*)',
targetLabel: 'stackdriver',
replacement: 'true',
action: 'replace'
}
],
// try to add the following in replacement of above in steps/step1.ts
// metricRelabelings: [
// {
// sourceLabels: ['__name__'],
// regex: 'typhoon_(.*)',
// targetLabel: 'stackdriver',
// replacement: 'true',
// action: 'replace'
// }
// ]
const myMonitoring = prometheusOperator.service.apply(service => {
return new k8s.apiextensions.CustomResource('my-monitoring', {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
spec: {
selector: {
matchLabels: { app: 'my-app' },
},
],
},
}, {dependsOn: prometheusOperator});
endpoints: [
{
port: 'http',
interval: '65s',
// start with the following
relabelings: [
{
regex: '(.*)',
targetLabel: 'stackdriver',
replacement: 'true',
action: 'replace'
}
],
// try to add the following in replacement of above in steps/step1.ts
// metricRelabelings: [
// {
// sourceLabels: ['__name__'],
// regex: 'typhoon_(.*)',
// targetLabel: 'stackdriver',
// replacement: 'true',
// action: 'replace'
// }
// ]
},
],
},
}, {dependsOn: service});
})
export const myMonitoringName = myMonitoring.id;
97 changes: 44 additions & 53 deletions tests/examples/prometheus-operator/step1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,66 @@ import * as pulumi from "@pulumi/pulumi";
// PrometheusOperatorArgs are the options to configure on the CoreOS
// PrometheusOperator.
interface PrometheusOperatorArgs {
namespace: pulumi.Input<string>;
version?: string;
}

// PrometheusOperator implements the CoreOS Prometheus Operator.
export class PrometheusOperator extends pulumi.ComponentResource {
class PrometheusOperator extends pulumi.ComponentResource {
public readonly configFile: k8s.yaml.ConfigFile;
public readonly service: pulumi.Output<k8s.core.v1.Service>;
constructor(
name: string,
args: PrometheusOperatorArgs,
opts?: pulumi.ComponentResourceOptions,
) {
super('pulumi:monitoring/v1:PrometheusOperator', name, {}, opts);

this.configFile = new k8s.yaml.ConfigFile(
name,
{
file: `https://github.com/coreos/prometheus-operator/raw/release-${args.version || '0.38'}/bundle.yaml`,
transformations: [
obj => {
if (obj.metadata.namespace) {
obj.metadata.namespace = args.namespace;
}
if (obj.kind === 'ClusterRoleBinding') {
obj.subjects[0].namespace = args.namespace;
}
},
],
}, { parent: this });
this.configFile = new k8s.yaml.ConfigFile(name, {
file: `https://github.com/coreos/prometheus-operator/raw/release-${args.version || '0.38'}/bundle.yaml`,
}, {parent: this});

this.service = this.configFile.getResource("v1/Service", "default", "prometheus-operator");
}
}

// Create the Prometheus Operator.
const prometheusOperator = new PrometheusOperator("prometheus", {
namespace: "default",
});
const prometheusOperator = new PrometheusOperator("prometheus", {});

// Create the Prometheus Operator ServiceMonitor.
const myMonitoring = new k8s.apiextensions.CustomResource('my-monitoring', {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
spec: {
selector: {
matchLabels: { app: 'my-app' },
},
endpoints: [
{
port: 'http',
interval: '65s',
// removing the following in index.ts in favor of below
// relabelings: [
// {
// regex: '(.*)',
// targetLabel: 'stackdriver',
// replacement: 'true',
// action: 'replace'
// }
// ],
// add the following in replacement of above in index.ts
metricRelabelings: [
{
sourceLabels: ['__name__'],
regex: 'typhoon_(.*)',
targetLabel: 'stackdriver',
replacement: 'true',
action: 'replace'
}
]
const myMonitoring = prometheusOperator.service.apply(service => {
return new k8s.apiextensions.CustomResource('my-monitoring', {
apiVersion: 'monitoring.coreos.com/v1',
kind: 'ServiceMonitor',
spec: {
selector: {
matchLabels: { app: 'my-app' },
},
],
},
}, {dependsOn: prometheusOperator});
endpoints: [
{
port: 'http',
interval: '65s',
// removing the following in index.ts in favor of below
// relabelings: [
// {
// regex: '(.*)',
// targetLabel: 'stackdriver',
// replacement: 'true',
// action: 'replace'
// }
// ],
// add the following in replacement of above in index.ts
metricRelabelings: [
{
sourceLabels: ['__name__'],
regex: 'typhoon_(.*)',
targetLabel: 'stackdriver',
replacement: 'true',
action: 'replace'
}
]
},
],
},
}, {dependsOn: service});
})
export const myMonitoringName = myMonitoring.id;

0 comments on commit 4c10d59

Please sign in to comment.