Skip to content

Commit 21dc4c4

Browse files
authored
feat: Add Kubernetes/IKS support (#304)
1 parent 948e0c9 commit 21dc4c4

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
77
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
88

9-
This module deploys the following observability agents to a Red Hat OpenShift Container Platform cluster:
9+
This module deploys the following observability agents to a Red Hat OpenShift Container Platform or Kubernetes cluster:
1010

1111
- [Logging agent](https://cloud.ibm.com/docs/log-analysis?topic=log-analysis-log_analysis_agent)
1212
- [Monitoring agent](https://cloud.ibm.com/docs/monitoring?topic=monitoring-about-collect-metrics)

chart/logdna-agent/templates/scc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
12
kind: SecurityContextConstraints
23
apiVersion: security.openshift.io/v1
34
metadata:
@@ -52,3 +53,4 @@ volumes:
5253
- persistentVolumeClaim
5354
- projected
5455
- secret
56+
{{- end }}

chart/sysdig-agent/templates/scc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- if .Capabilities.APIVersions.Has "security.openshift.io/v1/SecurityContextConstraints" }}
12
kind: SecurityContextConstraints
23
apiVersion: security.openshift.io/v1
34
metadata:
@@ -38,3 +39,4 @@ users:
3839
- system:serviceaccount:{{ .Release.Namespace }}:{{ .Values.metadata.name }}
3940
volumes:
4041
- '*'
42+
{{- end }}

examples/basic/main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ resource "ibm_is_subnet" "testacc_subnet" {
5757
}
5858

5959
resource "ibm_resource_instance" "cos_instance" {
60+
count = var.is_openshift ? 1 : 0
6061
name = "${var.prefix}-cos"
6162
service = "cloud-object-storage"
6263
plan = "standard"
@@ -68,18 +69,19 @@ resource "ibm_resource_instance" "cos_instance" {
6869
# Lookup the current default kube version
6970
data "ibm_container_cluster_versions" "cluster_versions" {}
7071
locals {
71-
default_ocp_version = "${data.ibm_container_cluster_versions.cluster_versions.default_openshift_version}_openshift"
72+
default_version = var.is_openshift ? "${data.ibm_container_cluster_versions.cluster_versions.default_openshift_version}_openshift" : data.ibm_container_cluster_versions.cluster_versions.default_kube_version
7273
}
7374

7475
resource "ibm_container_vpc_cluster" "cluster" {
7576
name = var.prefix
7677
vpc_id = ibm_is_vpc.example_vpc.id
77-
kube_version = local.default_ocp_version
78+
kube_version = local.default_version
7879
flavor = "bx2.4x16"
7980
worker_count = "2"
80-
entitlement = "cloud_pak"
81-
cos_instance_crn = ibm_resource_instance.cos_instance.id
81+
entitlement = var.is_openshift ? "cloud_pak" : null
82+
cos_instance_crn = var.is_openshift ? ibm_resource_instance.cos_instance[0].id : null
8283
force_delete_storage = true
84+
wait_till = "Normal"
8385
zones {
8486
subnet_id = ibm_is_subnet.testacc_subnet.id
8587
name = "${var.region}-1"

examples/basic/provider.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ provider "kubernetes" {
2626

2727
provider "helm" {
2828
kubernetes {
29-
host = data.ibm_container_cluster_config.cluster_config.host
30-
token = data.ibm_container_cluster_config.cluster_config.token
29+
host = data.ibm_container_cluster_config.cluster_config.host
30+
token = data.ibm_container_cluster_config.cluster_config.token
31+
cluster_ca_certificate = data.ibm_container_cluster_config.cluster_config.ca_certificate
3132
}
3233
}

examples/basic/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "ibmcloud_api_key" {
44
sensitive = true
55
}
66

7+
variable "is_openshift" {
8+
type = bool
9+
description = "Defines whether this is an OpenShift or Kubernetes cluster"
10+
default = true
11+
}
12+
713
variable "prefix" {
814
type = string
915
description = "Prefix for name of all resource created by this example"

tests/pr_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,16 @@ func TestRunUpgrade(t *testing.T) {
7373
assert.NotNil(t, output, "Expected some output")
7474
}
7575
}
76+
77+
func TestRunBasicAgentsKubernetes(t *testing.T) {
78+
t.Parallel()
79+
80+
var extTerraformVarsK8s = map[string]interface{}{}
81+
extTerraformVarsK8s["is_openshift"] = false
82+
83+
options := setupOptions(t, "basic-obs-agents-k8s", terraformDirOther, extTerraformVarsK8s)
84+
85+
output, err := options.RunTestConsistency()
86+
assert.Nil(t, err, "This should not have errored")
87+
assert.NotNil(t, output, "Expected some output")
88+
}

0 commit comments

Comments
 (0)