phantomjinx commented on a change in pull request #2284: URL: https://github.com/apache/camel-k/pull/2284#discussion_r677624799
########## File path: config/Makefile ########## @@ -0,0 +1,376 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# Allows for resources to be loaded from outside the root location of +# the kustomize config file. Ensures that resource don't need to be +# copied around the file system. +# +# See https://kubectl.docs.kubernetes.io/faq/kustomize +# +KOPTIONS := --load-restrictor LoadRestrictionsNone + +# +# Include the main camel-k Makefile containing +# basic common recipes like kustomize and vars +# like VERSION +# +include script/Makefile + +# +# Vars that can be overridden by external env vars +# +DEBUG ?= false +TAG ?= $(VERSION) +NAMESPACE ?= camel-k + +# Image pull policy: [IfNotPresent|Always] +IMAGE_PULL_POLICY ?= IfNotPresent +# Global: [true|false] +# - On setup: will promote roles and bindings to cluster-level +# - On operator: set namespace to all using WATCH_NAMESPACE env var +GLOBAL ?= false +# Monitoring: [true|false] +# - On operator: will add the prometheus resources to install +MONITORING ?= false +# Monitoring Port: integer +MONITORING_PORT ?= 8080 +# Health Port: integer +HEALTH_PORT ?= 8081 + +RBAC_KUBE := rbac/kubernetes +RBAC_OS := rbac/openshift +RBAC_CLUSTER := cluster +RBAC_GLOBAL := global +INFRASTRUCTURE := infrastructure +YAML := yaml + +OP_PATCHES := ./operator/patches +PLATFORM_PATCHES := ./platform/patches +PLACEHOLDER := placeholder +IMAGE_PULL_POLICY_PATCH := image-pull-policy-always-patch +WATCH_NAMESPACE_PATCH := watch-namespace-global-patch +PORTS_PATCH := ports-patch +INT_PLATFORM_PATCH := integration-platform-patch + +# +# Macro for editing kustomization to define +# the image reference +# +# Parameter: directory of the kustomization.yaml +# +define set-kustomize-image + $(if $(filter $(DEFAULT_IMAGE),$(IMAGE_NAME):$(TAG)),,\ + @cd $(1) && $(KUSTOMIZE) edit set image $(DEFAULT_IMAGE)=$(IMAGE_NAME):$(TAG)) +endef + +# +# Macro for editing kustomization to define +# the namespace +# +# Parameter: directory of the kustomization.yaml +# +define set-kustomize-namespace + @cd $(1) && $(KUSTOMIZE) edit set namespace $(NAMESPACE) +endef + +# +# Macro for swapping a resource directory to an alternative directory +# +# Parameters: +# * directory of the kustomization.yaml +# * source directory +# * target directory +# +define swap-rbac + @cd $(1) && \ + $(KUSTOMIZE) edit remove resource ../$(2) && \ + $(KUSTOMIZE) edit add resource ../$(3) +endef + +# +# Add or remove a patch on a kustomization.yaml +# targetting the deployment resource +# +# Parameters: +# * directory of the kustomization.yaml +# * [add, remove] +# * path of patch +# +define add-remove-deployment-patch + @cd $(1) && \ + $(KUSTOMIZE) edit $(2) patch --path patches/$(3) --kind Deployment --name camel-k-operator +endef + +# +# Macro for adding / removing the prometheus resources for monitoring +# +define add-remove-operator-monitoring + cd $(1) && \ + $(KUSTOMIZE) edit $(2) resource ../prometheus +endef + +.PHONY: have-platform check_admin setup-cluster .setup-kubernetes .setup-openshift setup + +# +# Determine the platform of the cluster based on +# either the use of querying through a go-client +# or using an installed client, ie. oc or kubectl +# +find-platform: +ifndef PLATFORM +PLATFORM=$(shell script/check_platform.sh) +endif + +# +# Checks if the cluster platform has been defined correctly either by the user +# or by the platform_check script. +# +have-platform: find-platform +ifeq ($(PLATFORM),openshift) + @echo Platform identified as 'openshift' +else ifeq ($(PLATFORM),kubernetes) + @echo Platform identified as 'kubernetes' +else + @echo "****" + @echo "**** ERROR: Cannot continue as cluster platform cannot be identified ****" + @echo "****" + @exit 1 +endif + +# +# Checks if the cluster user has the necessary privileges to be a cluster-admin +# In this case if the user can list the CRDs then probably a cluster-admin +# +check-admin: kubectl + @output=$$(kubectl get crd 2>&1) || (echo "****" && echo "**** ERROR: Cannot continue as user is not a Cluster-Admin ****" && echo "****"; exit 1) + +# +# Setup the cluster installation by installing crds and cluster roles. +# +# Will either call setup-cluster-openshift (then setup-cluster-kubernetes) or +# setup-cluster-kubernetes depending on the identity of the cluster +# +# PARAMETERS: +# NAMESPACE: Sets the namespace for the resources +# PLATFORM: Override the discovered platform, if required +# DEBUG: true - Prints the resources to be applied instead of applying them +# +setup-cluster: have-platform kustomize kubectl check-admin +# Set the namespace in the setup-cluster kustomization yaml + @$(call set-kustomize-namespace,$@) Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
