def start_charm(): layer.status.maintenance('configuring workload') # fetch the info (registry path, auth info) about the images image1_info = layer.docker_resource.get_info('my-image') image2_info = layer.docker_resource.get_info('my-other-image') # this can also be handed raw YAML, so some charm authors # choose to use templated YAML in a file instead layer.caas_base.pod_spec_set({ 'containers': [ { 'name': 'k8s-charm-template-service1', 'imageDetails': { 'imagePath': image1_info.registry_path, 'username': image1_info.username, 'password': image1_info.password, }, 'command': [], 'ports': [ { 'name': 'website1', 'containerPort': 80, }, ], 'config': { 'MY_ENV_VAR': hookenv.model_name(), }, }, { 'name': 'k8s-charm-template-service2', 'imageDetails': { 'imagePath': image2_info.registry_path, 'username': image2_info.username, 'password': image2_info.password, }, 'command': [], 'ports': [ { 'name': 'website2', 'containerPort': 8080, }, ], 'config': { 'MY_ENV_VAR': hookenv.model_name(), }, }, ], }) # juju should set the status to active once the workload # pod is up and running (I think?) layer.status.maintenance('starting workload') set_flag('charm.k8s-charm-template.started')
def start_charm(): layer.status.maintenance('starting workload') # fetch the image info (registry path, auth info) image_info = layer.docker_resource.get_info('coredns-image') config = hookenv.config() port = config.get('port') layer.caas_base.pod_spec_set({ 'containers': [ { 'name': 'coredns-service', 'imageDetails': { 'imagePath': image_info.registry_path, 'username': image_info.username, 'password': image_info.password, }, 'command': ['/coredns', '-dns.port={}'.format(port)], 'ports': [ { 'name': 'dns', 'containerPort': 1053, }, ], 'config': { 'K8S_MODEL': hookenv.model_name(), }, }, ], }) layer.status.active('ready') set_flag('charm.coredns.started')
def add_iperf_concurrency_metric(self, src_unit, dst_unit, value, tag): if 'magpie_iperf_concurrency' not in self.metrics: self.metrics['magpie_iperf_concurrency'] = Gauge( 'magpie_iperf_concurrency', 'magpie iperf process concurrency', ['model', 'src', 'dest', 'tag'] ) self.metrics['magpie_iperf_concurrency'].labels( model=hookenv.model_name(), src=src_unit, dest=dst_unit, tag=tag).set(value)
def scrape_available(scrape): if hookenv.config().get("ingress"): scrape.configure( port=10254, labels=dict( juju_model=hookenv.model_name(), juju_model_uuid=hookenv.model_uuid(), juju_application=hookenv.application_name(), juju_unit=hookenv.local_unit(), service="nginx-ingress", ), )
def add_iperf_bandwidth_metric(self, src_unit, dst_unit, value, tag): """ labels: fio_{read|write}_{iops,bandwidth,latency} rbd_bench_{read|write}_?? rados_bench_{read|write}_?? """ if 'magpie_iperf_bandwidth' not in self.metrics: self.metrics['magpie_iperf_bandwidth'] = Gauge( 'magpie_iperf_bandwidth', 'magpie iperf bandwidth (bits/s)', ['model', 'src', 'dest', 'tag'] ) self.metrics['magpie_iperf_bandwidth'].labels( model=hookenv.model_name(), src=src_unit, dest=dst_unit, tag=tag).set(value)
def make_pod_spec(): """Generate the pod spec. """ md = metadata() cfg = config() image_info = layer.docker_resource.get_info(ECK_OPERATOR) roles = get_roles_from_yaml() operator = get_operator_from_yaml() operator_namespace = model_name() operator_roles = cfg.get('operator-roles') service_account_name = application_name() service_name = md.get('name') spec = operator['spec']['template']['spec'] container = spec['containers'][0] operator_ports = container['ports'] operator_resources = container['resources'] termination_grace_period_seconds = spec['terminationGracePeriodSeconds'] pod_spec = { 'version': 2, 'containers': [ { 'name': service_name, 'args': [ "manager", "--operator-roles", operator_roles, "--operator-namespace", operator_namespace, "--enable-debug-logs=false", ], 'imageDetails': { 'imagePath': image_info.registry_path, 'username': image_info.username, 'password': image_info.password, }, 'imagePullPolicy': "IfNotPresent", 'config': { 'OPERATOR_NAMESPACE': operator_namespace, 'WEBHOOK_SECRET': "webhook-server-secret", 'WEBHOOK_PODS_LABEL': "elastic-operator", 'OPERATOR_IMAGE': image_info.registry_path, }, 'resources': operator_resources, 'ports': operator_ports, 'terminationMessagePath': "/dev/termination-log", 'terminationMessagePolicy': "File", }, ], 'dnsPolicy': "ClusterFirst", 'restartPolicy': "Always", 'serviceAccountName': service_account_name, 'serviceAccountRoles': { 'automountServiceAccountToken': True, 'rules': roles, }, 'terminationGracePeriodSeconds': termination_grace_period_seconds, } return pod_spec