remove kubectl manifests bc drone is not happy running them :/
This commit is contained in:
parent
ead58dfc99
commit
9292b3285f
9 changed files with 448 additions and 300 deletions
30
modules/kubernetes/dbaas/cluster.yaml
Normal file
30
modules/kubernetes/dbaas/cluster.yaml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
apiVersion: mysql.presslabs.org/v1alpha1
|
||||
kind: MysqlCluster
|
||||
metadata:
|
||||
name: mysql-cluster
|
||||
namespace: dbaas
|
||||
spec:
|
||||
mysqlVersion: "5.7"
|
||||
replicas: 1
|
||||
secretName: cluster-secret
|
||||
mysqlConf:
|
||||
# read_only: 0 # mysql forms a single transaction for each sql statement, autocommit for each statement
|
||||
# automatic_sp_privileges: "ON" # automatically grants the EXECUTE and ALTER ROUTINE privileges to the creator of a stored routine
|
||||
# auto_generate_certs: "ON" # Auto Generation of Certificate
|
||||
# auto_increment_increment: 1 # Auto Incrementing value from +1
|
||||
# auto_increment_offset: 1 # Auto Increment Offset
|
||||
# binlog-format: "STATEMENT" # contains various options such ROW(SLOW,SAFE) STATEMENT(FAST,UNSAFE), MIXED(combination of both)
|
||||
# wait_timeout: 31536000 # 28800 number of seconds the server waits for activity on a non-interactive connection before closing it, You might encounter MySQL server has gone away error, you then tweak this value acccordingly
|
||||
# interactive_timeout: 28800 # The number of seconds the server waits for activity on an interactive connection before closing it.
|
||||
# max_allowed_packet: "512M" # Maximum size of MYSQL Network protocol packet that the server can create or read 4MB, 8MB, 16MB, 32MB
|
||||
# max-binlog-size: 1073741824 # binary logs contains the events that describe database changes, this parameter describe size for the bin_log file.
|
||||
# log_output: "TABLE" # Format in which the logout will be dumped
|
||||
# master-info-repository: "TABLE" # Format in which the master info will be dumped
|
||||
# relay_log_info_repository: "TABLE" # Format in which the relay info will be dumped
|
||||
volumeSpec:
|
||||
persistentVolumeClaim:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
|
|
@ -9,19 +9,20 @@ variable "prod" {
|
|||
type = bool
|
||||
}
|
||||
|
||||
provider "kubectl" {
|
||||
# config_path = var.prod ? "" : "~/.kube/config"
|
||||
host = "https://kubernetes:6443"
|
||||
insecure = true
|
||||
# load_config_file = !var.prod
|
||||
# config_context = "kubernetes-admin@kubernetes"
|
||||
# provider "kubectl" {
|
||||
# config_path = var.prod ? "" : "~/.kube/config"
|
||||
# host = "https://kubernetes:6443"
|
||||
# insecure = true
|
||||
# load_config_file = !var.prod
|
||||
# config_context = "kubernetes-admin@kubernetes"
|
||||
# config_context = "kek"
|
||||
|
||||
# client_certificate = var.prod ? "/run/secrets/kubernetes.io/serviceaccount/ca.crt" : ""
|
||||
# token = var.prod ? "/run/secrets/kubernetes.io/serviceaccount/token" : ""
|
||||
# insecure = true
|
||||
# insecure = true
|
||||
# client_certificate = var.prod ? "/run/secrets/kubernetes.io/serviceaccount/ca.crt" : ""
|
||||
# token = var.prod ? "/run/secrets/kubernetes.io/serviceaccount/token" : ""
|
||||
# insecure = true
|
||||
# insecure = true
|
||||
|
||||
}
|
||||
# }
|
||||
resource "kubernetes_namespace" "dbaas" {
|
||||
metadata {
|
||||
name = "dbaas"
|
||||
|
|
@ -239,237 +240,237 @@ resource "kubernetes_ingress" "phpmyadmin" {
|
|||
}
|
||||
|
||||
|
||||
resource "kubectl_manifest" "mysql-cluster" {
|
||||
yaml_body = <<-YAML
|
||||
apiVersion: mysql.presslabs.org/v1alpha1
|
||||
kind: MysqlCluster
|
||||
metadata:
|
||||
name: mysql-cluster
|
||||
namespace: dbaas
|
||||
spec:
|
||||
mysqlVersion: "5.7"
|
||||
replicas: 1
|
||||
secretName: cluster-secret
|
||||
mysqlConf:
|
||||
# read_only: 0 # mysql forms a single transaction for each sql statement, autocommit for each statement
|
||||
# automatic_sp_privileges: "ON" # automatically grants the EXECUTE and ALTER ROUTINE privileges to the creator of a stored routine
|
||||
# auto_generate_certs: "ON" # Auto Generation of Certificate
|
||||
# auto_increment_increment: 1 # Auto Incrementing value from +1
|
||||
# auto_increment_offset: 1 # Auto Increment Offset
|
||||
# binlog-format: "STATEMENT" # contains various options such ROW(SLOW,SAFE) STATEMENT(FAST,UNSAFE), MIXED(combination of both)
|
||||
# wait_timeout: 31536000 # 28800 number of seconds the server waits for activity on a non-interactive connection before closing it, You might encounter MySQL server has gone away error, you then tweak this value acccordingly
|
||||
# interactive_timeout: 28800 # The number of seconds the server waits for activity on an interactive connection before closing it.
|
||||
# max_allowed_packet: "512M" # Maximum size of MYSQL Network protocol packet that the server can create or read 4MB, 8MB, 16MB, 32MB
|
||||
# max-binlog-size: 1073741824 # binary logs contains the events that describe database changes, this parameter describe size for the bin_log file.
|
||||
# log_output: "TABLE" # Format in which the logout will be dumped
|
||||
# master-info-repository: "TABLE" # Format in which the master info will be dumped
|
||||
# relay_log_info_repository: "TABLE" # Format in which the relay info will be dumped
|
||||
volumeSpec:
|
||||
persistentVolumeClaim:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
YAML
|
||||
depends_on = [helm_release.mysql]
|
||||
# manifest = {
|
||||
# apiVersion = "mysql.presslabs.org/v1alpha1"
|
||||
# kind = "MysqlCluster"
|
||||
# metadata = {
|
||||
# name = "mysql-cluster"
|
||||
# namespace = "dbaas"
|
||||
# }
|
||||
# spec = {
|
||||
# mysqlVersion = "5.7"
|
||||
# replicas = 1
|
||||
# secretName = "cluster-secret"
|
||||
# mysqlConf = {
|
||||
# read_only = 0
|
||||
# }
|
||||
# volumeSpec = {
|
||||
# persistentVolumeClaim = {
|
||||
# resources = {
|
||||
# requests = {
|
||||
# storage = "10Gi"
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
}
|
||||
# resource "kubectl_manifest" "mysql-cluster" {
|
||||
# yaml_body = <<-YAML
|
||||
# apiVersion: mysql.presslabs.org/v1alpha1
|
||||
# kind: MysqlCluster
|
||||
# metadata:
|
||||
# name: mysql-cluster
|
||||
# namespace: dbaas
|
||||
# spec:
|
||||
# mysqlVersion: "5.7"
|
||||
# replicas: 1
|
||||
# secretName: cluster-secret
|
||||
# mysqlConf:
|
||||
# # read_only: 0 # mysql forms a single transaction for each sql statement, autocommit for each statement
|
||||
# # automatic_sp_privileges: "ON" # automatically grants the EXECUTE and ALTER ROUTINE privileges to the creator of a stored routine
|
||||
# # auto_generate_certs: "ON" # Auto Generation of Certificate
|
||||
# # auto_increment_increment: 1 # Auto Incrementing value from +1
|
||||
# # auto_increment_offset: 1 # Auto Increment Offset
|
||||
# # binlog-format: "STATEMENT" # contains various options such ROW(SLOW,SAFE) STATEMENT(FAST,UNSAFE), MIXED(combination of both)
|
||||
# # wait_timeout: 31536000 # 28800 number of seconds the server waits for activity on a non-interactive connection before closing it, You might encounter MySQL server has gone away error, you then tweak this value acccordingly
|
||||
# # interactive_timeout: 28800 # The number of seconds the server waits for activity on an interactive connection before closing it.
|
||||
# # max_allowed_packet: "512M" # Maximum size of MYSQL Network protocol packet that the server can create or read 4MB, 8MB, 16MB, 32MB
|
||||
# # max-binlog-size: 1073741824 # binary logs contains the events that describe database changes, this parameter describe size for the bin_log file.
|
||||
# # log_output: "TABLE" # Format in which the logout will be dumped
|
||||
# # master-info-repository: "TABLE" # Format in which the master info will be dumped
|
||||
# # relay_log_info_repository: "TABLE" # Format in which the relay info will be dumped
|
||||
# volumeSpec:
|
||||
# persistentVolumeClaim:
|
||||
# accessModes:
|
||||
# - ReadWriteOnce
|
||||
# resources:
|
||||
# requests:
|
||||
# storage: 10Gi
|
||||
# YAML
|
||||
# depends_on = [helm_release.mysql]
|
||||
# # manifest = {
|
||||
# # apiVersion = "mysql.presslabs.org/v1alpha1"
|
||||
# # kind = "MysqlCluster"
|
||||
# # metadata = {
|
||||
# # name = "mysql-cluster"
|
||||
# # namespace = "dbaas"
|
||||
# # }
|
||||
# # spec = {
|
||||
# # mysqlVersion = "5.7"
|
||||
# # replicas = 1
|
||||
# # secretName = "cluster-secret"
|
||||
# # mysqlConf = {
|
||||
# # read_only = 0
|
||||
# # }
|
||||
# # volumeSpec = {
|
||||
# # persistentVolumeClaim = {
|
||||
# # resources = {
|
||||
# # requests = {
|
||||
# # storage = "10Gi"
|
||||
# # }
|
||||
# # }
|
||||
# # }
|
||||
# # }
|
||||
# # }
|
||||
# # }
|
||||
# }
|
||||
|
||||
|
||||
# For some unknwown reason not all CRDs are installed. Add them manually
|
||||
resource "kubectl_manifest" "mysql-user" {
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
controller-gen.kubebuilder.io/version: v0.5.0
|
||||
helm.sh/hook: crd-install
|
||||
name: mysqlusers.mysql.presslabs.org
|
||||
labels:
|
||||
app: mysql-operator
|
||||
spec:
|
||||
group: mysql.presslabs.org
|
||||
names:
|
||||
kind: MysqlUser
|
||||
listKind: MysqlUserList
|
||||
plural: mysqlusers
|
||||
singular: mysqluser
|
||||
scope: Namespaced
|
||||
versions:
|
||||
- additionalPrinterColumns:
|
||||
- description: The user status
|
||||
jsonPath: .status.conditions[?(@.type == 'Ready')].status
|
||||
name: Ready
|
||||
type: string
|
||||
- jsonPath: .spec.clusterRef.name
|
||||
name: Cluster
|
||||
type: string
|
||||
- jsonPath: .spec.user
|
||||
name: UserName
|
||||
type: string
|
||||
- jsonPath: .metadata.creationTimestamp
|
||||
name: Age
|
||||
type: date
|
||||
name: v1alpha1
|
||||
schema:
|
||||
openAPIV3Schema:
|
||||
description: MysqlUser is the Schema for the MySQL User API
|
||||
properties:
|
||||
apiVersion:
|
||||
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||
type: string
|
||||
kind:
|
||||
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||
type: string
|
||||
metadata:
|
||||
type: object
|
||||
spec:
|
||||
description: MysqlUserSpec defines the desired state of MysqlUserSpec
|
||||
properties:
|
||||
allowedHosts:
|
||||
description: AllowedHosts is the allowed host to connect from.
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
clusterRef:
|
||||
description: ClusterRef represents a reference to the MySQL cluster. This field should be immutable.
|
||||
properties:
|
||||
name:
|
||||
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
|
||||
type: string
|
||||
namespace:
|
||||
description: Namespace the MySQL cluster namespace
|
||||
type: string
|
||||
type: object
|
||||
password:
|
||||
description: Password is the password for the user.
|
||||
properties:
|
||||
key:
|
||||
description: The key of the secret to select from. Must be a valid secret key.
|
||||
type: string
|
||||
name:
|
||||
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
|
||||
type: string
|
||||
optional:
|
||||
description: Specify whether the Secret or its key must be defined
|
||||
type: boolean
|
||||
required:
|
||||
- key
|
||||
type: object
|
||||
permissions:
|
||||
description: Permissions is the list of roles that user has in the specified database.
|
||||
items:
|
||||
description: MysqlPermission defines a MySQL schema permission
|
||||
properties:
|
||||
permissions:
|
||||
description: Permissions represents the permissions granted on the schema/tables
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
schema:
|
||||
description: Schema represents the schema to which the permission applies
|
||||
type: string
|
||||
tables:
|
||||
description: Tables represents the tables inside the schema to which the permission applies
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
required:
|
||||
- permissions
|
||||
- schema
|
||||
- tables
|
||||
type: object
|
||||
type: array
|
||||
resourceLimits:
|
||||
additionalProperties:
|
||||
anyOf:
|
||||
- type: integer
|
||||
- type: string
|
||||
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
|
||||
x-kubernetes-int-or-string: true
|
||||
description: 'ResourceLimits allow settings limit per mysql user as defined here: https://dev.mysql.com/doc/refman/5.7/en/user-resources.html'
|
||||
type: object
|
||||
user:
|
||||
description: User is the name of the user that will be created with will access the specified database. This field should be immutable.
|
||||
type: string
|
||||
required:
|
||||
- allowedHosts
|
||||
- clusterRef
|
||||
- password
|
||||
- user
|
||||
type: object
|
||||
status:
|
||||
description: MysqlUserStatus defines the observed state of MysqlUser
|
||||
properties:
|
||||
allowedHosts:
|
||||
description: AllowedHosts contains the list of hosts that the user is allowed to connect from.
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
conditions:
|
||||
description: Conditions represents the MysqlUser resource conditions list.
|
||||
items:
|
||||
description: MySQLUserCondition defines the condition struct for a MysqlUser resource
|
||||
properties:
|
||||
lastTransitionTime:
|
||||
description: Last time the condition transitioned from one status to another.
|
||||
format: date-time
|
||||
type: string
|
||||
lastUpdateTime:
|
||||
description: The last time this condition was updated.
|
||||
format: date-time
|
||||
type: string
|
||||
message:
|
||||
description: A human readable message indicating details about the transition.
|
||||
type: string
|
||||
reason:
|
||||
description: The reason for the condition's last transition.
|
||||
type: string
|
||||
status:
|
||||
description: Status of the condition, one of True, False, Unknown.
|
||||
type: string
|
||||
type:
|
||||
description: Type of MysqlUser condition.
|
||||
type: string
|
||||
required:
|
||||
- lastTransitionTime
|
||||
- message
|
||||
- reason
|
||||
- status
|
||||
- type
|
||||
type: object
|
||||
type: array
|
||||
type: object
|
||||
type: object
|
||||
served: true
|
||||
storage: true
|
||||
subresources:
|
||||
status: {}
|
||||
EOF
|
||||
}
|
||||
# resource "kubectl_manifest" "mysql-user" {
|
||||
# yaml_body = <<-EOF
|
||||
# apiVersion: apiextensions.k8s.io/v1
|
||||
# kind: CustomResourceDefinition
|
||||
# metadata:
|
||||
# annotations:
|
||||
# controller-gen.kubebuilder.io/version: v0.5.0
|
||||
# helm.sh/hook: crd-install
|
||||
# name: mysqlusers.mysql.presslabs.org
|
||||
# labels:
|
||||
# app: mysql-operator
|
||||
# spec:
|
||||
# group: mysql.presslabs.org
|
||||
# names:
|
||||
# kind: MysqlUser
|
||||
# listKind: MysqlUserList
|
||||
# plural: mysqlusers
|
||||
# singular: mysqluser
|
||||
# scope: Namespaced
|
||||
# versions:
|
||||
# - additionalPrinterColumns:
|
||||
# - description: The user status
|
||||
# jsonPath: .status.conditions[?(@.type == 'Ready')].status
|
||||
# name: Ready
|
||||
# type: string
|
||||
# - jsonPath: .spec.clusterRef.name
|
||||
# name: Cluster
|
||||
# type: string
|
||||
# - jsonPath: .spec.user
|
||||
# name: UserName
|
||||
# type: string
|
||||
# - jsonPath: .metadata.creationTimestamp
|
||||
# name: Age
|
||||
# type: date
|
||||
# name: v1alpha1
|
||||
# schema:
|
||||
# openAPIV3Schema:
|
||||
# description: MysqlUser is the Schema for the MySQL User API
|
||||
# properties:
|
||||
# apiVersion:
|
||||
# description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
|
||||
# type: string
|
||||
# kind:
|
||||
# description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
|
||||
# type: string
|
||||
# metadata:
|
||||
# type: object
|
||||
# spec:
|
||||
# description: MysqlUserSpec defines the desired state of MysqlUserSpec
|
||||
# properties:
|
||||
# allowedHosts:
|
||||
# description: AllowedHosts is the allowed host to connect from.
|
||||
# items:
|
||||
# type: string
|
||||
# type: array
|
||||
# clusterRef:
|
||||
# description: ClusterRef represents a reference to the MySQL cluster. This field should be immutable.
|
||||
# properties:
|
||||
# name:
|
||||
# description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
|
||||
# type: string
|
||||
# namespace:
|
||||
# description: Namespace the MySQL cluster namespace
|
||||
# type: string
|
||||
# type: object
|
||||
# password:
|
||||
# description: Password is the password for the user.
|
||||
# properties:
|
||||
# key:
|
||||
# description: The key of the secret to select from. Must be a valid secret key.
|
||||
# type: string
|
||||
# name:
|
||||
# description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
|
||||
# type: string
|
||||
# optional:
|
||||
# description: Specify whether the Secret or its key must be defined
|
||||
# type: boolean
|
||||
# required:
|
||||
# - key
|
||||
# type: object
|
||||
# permissions:
|
||||
# description: Permissions is the list of roles that user has in the specified database.
|
||||
# items:
|
||||
# description: MysqlPermission defines a MySQL schema permission
|
||||
# properties:
|
||||
# permissions:
|
||||
# description: Permissions represents the permissions granted on the schema/tables
|
||||
# items:
|
||||
# type: string
|
||||
# type: array
|
||||
# schema:
|
||||
# description: Schema represents the schema to which the permission applies
|
||||
# type: string
|
||||
# tables:
|
||||
# description: Tables represents the tables inside the schema to which the permission applies
|
||||
# items:
|
||||
# type: string
|
||||
# type: array
|
||||
# required:
|
||||
# - permissions
|
||||
# - schema
|
||||
# - tables
|
||||
# type: object
|
||||
# type: array
|
||||
# resourceLimits:
|
||||
# additionalProperties:
|
||||
# anyOf:
|
||||
# - type: integer
|
||||
# - type: string
|
||||
# pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
|
||||
# x-kubernetes-int-or-string: true
|
||||
# description: 'ResourceLimits allow settings limit per mysql user as defined here: https://dev.mysql.com/doc/refman/5.7/en/user-resources.html'
|
||||
# type: object
|
||||
# user:
|
||||
# description: User is the name of the user that will be created with will access the specified database. This field should be immutable.
|
||||
# type: string
|
||||
# required:
|
||||
# - allowedHosts
|
||||
# - clusterRef
|
||||
# - password
|
||||
# - user
|
||||
# type: object
|
||||
# status:
|
||||
# description: MysqlUserStatus defines the observed state of MysqlUser
|
||||
# properties:
|
||||
# allowedHosts:
|
||||
# description: AllowedHosts contains the list of hosts that the user is allowed to connect from.
|
||||
# items:
|
||||
# type: string
|
||||
# type: array
|
||||
# conditions:
|
||||
# description: Conditions represents the MysqlUser resource conditions list.
|
||||
# items:
|
||||
# description: MySQLUserCondition defines the condition struct for a MysqlUser resource
|
||||
# properties:
|
||||
# lastTransitionTime:
|
||||
# description: Last time the condition transitioned from one status to another.
|
||||
# format: date-time
|
||||
# type: string
|
||||
# lastUpdateTime:
|
||||
# description: The last time this condition was updated.
|
||||
# format: date-time
|
||||
# type: string
|
||||
# message:
|
||||
# description: A human readable message indicating details about the transition.
|
||||
# type: string
|
||||
# reason:
|
||||
# description: The reason for the condition's last transition.
|
||||
# type: string
|
||||
# status:
|
||||
# description: Status of the condition, one of True, False, Unknown.
|
||||
# type: string
|
||||
# type:
|
||||
# description: Type of MysqlUser condition.
|
||||
# type: string
|
||||
# required:
|
||||
# - lastTransitionTime
|
||||
# - message
|
||||
# - reason
|
||||
# - status
|
||||
# - type
|
||||
# type: object
|
||||
# type: array
|
||||
# type: object
|
||||
# type: object
|
||||
# served: true
|
||||
# storage: true
|
||||
# subresources:
|
||||
# status: {}
|
||||
# EOF
|
||||
# }
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = ">= 1.10.0"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
# terraform {
|
||||
# required_providers {
|
||||
# kubectl = {
|
||||
# source = "gavinbunney/kubectl"
|
||||
# version = ">= 1.10.0"
|
||||
# }
|
||||
# }
|
||||
# required_version = ">= 0.13"
|
||||
# }
|
||||
|
|
|
|||
51
modules/kubernetes/monitoring/server-power-cycle/main.py
Normal file
51
modules/kubernetes/monitoring/server-power-cycle/main.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
|
||||
import aiohttp
|
||||
|
||||
iDRAC_HOST = 'idrac'
|
||||
iDRAC_USER_ENV_VAR = 'idrac_user'
|
||||
iDRAC_PASSWORD_ENV_VAR = 'idrac_password'
|
||||
SHOULD_RUN = True
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logging.warning(f'signal {sig} received. shutting down gracefully...')
|
||||
global SHOULD_RUN
|
||||
SHOULD_RUN = False
|
||||
time.sleep(60)
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
# define signal handlers
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
user = os.environ.get(iDRAC_USER_ENV_VAR)
|
||||
if user is None:
|
||||
logging.critical('missing environment variable for idrac user'
|
||||
f' please set {iDRAC_USER_ENV_VAR}')
|
||||
return
|
||||
|
||||
password = os.environ.get(iDRAC_PASSWORD_ENV_VAR)
|
||||
if password is None:
|
||||
logging.critical('missing environment variable for idrac password'
|
||||
f' please set {iDRAC_PASSWORD_ENV_VAR}')
|
||||
return
|
||||
|
||||
logging.info('service initiated with credentials')
|
||||
return await monitor(user, password)
|
||||
|
||||
|
||||
async def monitor(user: str, password: str) -> None:
|
||||
while SHOULD_RUN:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# abandoned bc server cannot start itself when it's off :/
|
||||
asyncio.run(main())
|
||||
66
modules/kubernetes/monitoring/server-power-cycle/main.sh
Normal file
66
modules/kubernetes/monitoring/server-power-cycle/main.sh
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#!/bin/sh
|
||||
|
||||
tag=server-power-cycle-script
|
||||
logger -t $tag start $(date '+%F-%R')
|
||||
|
||||
if [ -f /tmp/server-power-cycle-lock ]; then
|
||||
logger -t $tag 'Script already running. exiting'
|
||||
exit 0
|
||||
fi
|
||||
touch /tmp/server-power-cycle-lock
|
||||
|
||||
|
||||
if [ -f /root/server-power-cycle/state.off ]; then
|
||||
logger -t $tag 'Server state set to off'
|
||||
while true; do
|
||||
sleep 60 # sleep 1 minute
|
||||
logger -t $tag 'Trying to connect to idrac system...'
|
||||
curl --connect-timeout 5 -s -k -u root:calvin -H"Content-type: application/json" -X GET https://192.168.1.4/redfish/v1/Chassis/System.Embedded.1/Power/PowerSupplies/PSU.Slot.2
|
||||
if [[ $? -eq 0 ]]; then
|
||||
logger -t $tag "Connected to idrac, assuming power is back on"
|
||||
logger -t $tag "Power supply restored, sending power on command"
|
||||
curl -s -k -u root:calvin -X POST -d '{"Action": "Reset", "ResetType": "On"}' -H"Content-type: application/json" https://192.168.1.4/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset
|
||||
rm /root/server-power-cycle/state.off
|
||||
|
||||
logger -t $tag end $(date '+%F-%R')
|
||||
rm /tmp/server-power-cycle-lock
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
voltage=$(curl -s -k -u root:calvin -H"Content-type: application/json" -X GET https://192.168.1.4/redfish/v1/Chassis/System.Embedded.1/Power/PowerSupplies/PSU.Slot.2 |jq .LineInputVoltage)
|
||||
# check input voltage on the pwoer supply connected to the outer system
|
||||
if [[ $voltage -gt 0 ]]; then
|
||||
logger -t $tag "power supply is on. exiting"
|
||||
logger -t $tag end $(date '+%F-%R')
|
||||
rm /tmp/server-power-cycle-lock
|
||||
exit 0
|
||||
fi
|
||||
|
||||
to_wait=30
|
||||
echo "Continuously checking power supply for the next $to_wait minutes"
|
||||
|
||||
for i in $(seq 30); do
|
||||
logger -t $tag "Sleeping a minute..Minute $i"
|
||||
sleep 60
|
||||
|
||||
# check input voltage on the pwoer supply connected to the outer system
|
||||
voltage=$(curl -s -k -u root:calvin -H"Content-type: application/json" -X GET https://192.168.1.4/redfish/v1/Chassis/System.Embedded.1/Power/PowerSupplies/PSU.Slot.2 |jq .LineInputVoltage)
|
||||
if [[ $voltage -gt 0 ]]; then
|
||||
logger -t $tag "power supply is on. exiting"
|
||||
|
||||
logger -t $tag end $(date '+%F-%R')
|
||||
rm /tmp/server-power-cycle-lock
|
||||
exit 0
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
logger -t $tag "Power supply did not come back, sending graceful shutdown signal"
|
||||
curl -s -k -u root:calvin -X POST -d '{"Action": "Reset", "ResetType": "GracefulShutdown"}' -H"Content-type: application/json" https://192.168.1.4/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset
|
||||
|
||||
touch /root/server-power-cycle/state.off
|
||||
rm /tmp/server-power-cycle-lock
|
||||
logger -t $tag end $(date '+%F-%R')
|
||||
|
|
@ -36,34 +36,34 @@ resource "kubernetes_secret" "mysql_config" {
|
|||
}
|
||||
|
||||
# this depends on the mysql installation
|
||||
resource "kubectl_manifest" "mysql-user" {
|
||||
yaml_body = <<-YAML
|
||||
apiVersion: mysql.presslabs.org/v1alpha1
|
||||
kind: MysqlUser
|
||||
metadata:
|
||||
name: shlink
|
||||
namespace: url
|
||||
spec:
|
||||
user: shlink
|
||||
clusterRef:
|
||||
name: mysql-cluster
|
||||
namespace: dbaas
|
||||
password:
|
||||
name: mysql-config
|
||||
key: password
|
||||
allowedHosts:
|
||||
- '%'
|
||||
YAML
|
||||
# permissions:
|
||||
# - schema: db-name-in-mysql
|
||||
# tables: ["table1", "table2"]
|
||||
# permissions:
|
||||
# - SELECT
|
||||
# - UPDATE
|
||||
# - CREATE
|
||||
# allowedHosts:
|
||||
# - localhost
|
||||
}
|
||||
# resource "kubectl_manifest" "mysql-user" {
|
||||
# yaml_body = <<-YAML
|
||||
# apiVersion: mysql.presslabs.org/v1alpha1
|
||||
# kind: MysqlUser
|
||||
# metadata:
|
||||
# name: shlink
|
||||
# namespace: url
|
||||
# spec:
|
||||
# user: shlink
|
||||
# clusterRef:
|
||||
# name: mysql-cluster
|
||||
# namespace: dbaas
|
||||
# password:
|
||||
# name: mysql-config
|
||||
# key: password
|
||||
# allowedHosts:
|
||||
# - '%'
|
||||
# YAML
|
||||
# # permissions:
|
||||
# # - schema: db-name-in-mysql
|
||||
# # tables: ["table1", "table2"]
|
||||
# # permissions:
|
||||
# # - SELECT
|
||||
# # - UPDATE
|
||||
# # - CREATE
|
||||
# # allowedHosts:
|
||||
# # - localhost
|
||||
# }
|
||||
|
||||
resource "kubernetes_deployment" "shlink" {
|
||||
metadata {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = ">= 1.10.0"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
# terraform {
|
||||
# required_providers {
|
||||
# kubectl = {
|
||||
# source = "gavinbunney/kubectl"
|
||||
# version = ">= 1.10.0"
|
||||
# }
|
||||
# }
|
||||
# required_version = ">= 0.13"
|
||||
# }
|
||||
|
|
|
|||
Binary file not shown.
24
versions.tf
24
versions.tf
|
|
@ -1,12 +1,12 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
kubernetes = {
|
||||
source = "hashicorp/kubernetes"
|
||||
}
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = ">= 1.10.0"
|
||||
}
|
||||
}
|
||||
required_version = ">= 0.13"
|
||||
}
|
||||
# terraform {
|
||||
# required_providers {
|
||||
# kubernetes = {
|
||||
# source = "hashicorp/kubernetes"
|
||||
# }
|
||||
# kubectl = {
|
||||
# source = "gavinbunney/kubectl"
|
||||
# version = ">= 1.10.0"
|
||||
# }
|
||||
# }
|
||||
# required_version = ">= 0.13"
|
||||
# }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue