-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(customresources): use a 3-way merge patch instead of strategic merge
CustomResources do not support [JSON strategic merges](https://tools.ietf.org/html/rfc6902) on patch updates. Instead, they require a [JSON 3-way merge patch](https://tools.ietf.org/html/rfc7386) to properly apply the patch. CustomResource kinds now are treated separately from other known k8s kinds in order to apply the proper patch. A new [CoreOS prometheus-operator](https://github.com/coreos/prometheus-operator) test with a step update is included to validate this update path.
- Loading branch information
Showing
8 changed files
with
265 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: prometheus-operator | ||
description: The CoreOS Prometheus Operator | ||
runtime: nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as k8s from "@pulumi/kubernetes"; | ||
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 { | ||
public readonly configFile: k8s.yaml.ConfigFile; | ||
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 }); | ||
} | ||
} | ||
|
||
// Create the Prometheus Operator. | ||
const prometheusOperator = new PrometheusOperator("prometheus", { | ||
namespace: "default", | ||
}); | ||
|
||
// 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' | ||
// } | ||
// ] | ||
}, | ||
], | ||
}, | ||
}, {dependsOn: prometheusOperator}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "prometheus-operator", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/kubernetes": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import * as k8s from "@pulumi/kubernetes"; | ||
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 { | ||
public readonly configFile: k8s.yaml.ConfigFile; | ||
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 }); | ||
} | ||
} | ||
|
||
// Create the Prometheus Operator. | ||
const prometheusOperator = new PrometheusOperator("prometheus", { | ||
namespace: "default", | ||
}); | ||
|
||
// 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' | ||
} | ||
] | ||
}, | ||
], | ||
}, | ||
}, {dependsOn: prometheusOperator}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} | ||
|