def create(body, meta, spec, status, **kwargs): api = K8SApi.from_env() logger.info("Creating deployment ...") deployment_data = create_deployment_data(meta, spec) kopf.adopt(deployment_data) # kopf.label(pod_data, {'application': 'kopf-example-10'}) deployment = Deployment(api, deployment_data) if deployment.exists(): deployment.update() else: deployment.create() logger.info("Creating deployment ... done!") logger.info("Creating service ...") service_data = create_service_data(meta, spec) kopf.adopt(service_data) service = Service(api, service_data) if service.exists(): service.update() else: service.create() logger.info("Creating service ... done!") api.session.close() return {'job1-status': 100}
def update(body, meta, spec, status, **kwargs): api = K8SApi.from_env() logger.info(f"Updating fog rollout {meta['name']} ...") deployment_data = create_deployment_data(meta, spec) kopf.adopt(deployment_data) deployment = Deployment(api, deployment_data) if deployment.exists(): logger.info(f"Updating deployment {deployment.name} ...") deployment.update() logger.info(f"Updating deployment {deployment.name} ... done!") else: logger.warning(f"Deployment {deployment.name} doesn't exist") logger.info(f"Creating deployment {deployment.name} ...") deployment.create() logger.info(f"Creating deployment {deployment.name} ... done!") service_data = create_service_data(meta, spec) kopf.adopt(service_data) service = Service(api, service_data) if service.exists(): logger.info(f"Updating service {service.name} ...") service.update() logger.info(f"Updating service {service.name} ... done!") else: logger.warning(f"Service {service.name} doesn't exist") logger.info(f"Creating service {service.name} ...") service.create() logger.info(f"Creating service {service.name} ... done!") logger.info(f"Updating fog rollout {meta['name']} ... done!") api.session.close() return {'job1-status': 100}