forked from elastic/elastic-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cloudnative ci automation (elastic#837)
This commit provides the relevant Jenkins CI automation to open Pull requests to kibana github repository in order to keep Cloud-Native teams manifests in sync with the manifests that are used into Fleet UI. For full information check elastic#706 Updated .ci/Jenkins file that is triggered upon PR requests of /elastic-agent/deploy/kubernetes/* changes Updated Makefile to add functionality needed to create the extra files for the new prs to kibana remote repository
- Loading branch information
Showing
8 changed files
with
169 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
ALL=elastic-agent-standalone elastic-agent-managed | ||
BEAT_VERSION=$(shell head -n 1 ../../version/docs/version.asciidoc | cut -c 17- ) | ||
|
||
.PHONY: generate-k8s $(ALL) | ||
#variables needed for ci-create-kubernetes-templates-pull-request | ||
ELASTIC_AGENT_REPO=kibana | ||
ELASTIC_AGENT_REPO_PATH=x-pack/plugins/fleet/server/services/ | ||
FILE_REPO=elastic_agent_manifest.ts | ||
ELASTIC_AGENT_BRANCH=update-k8s-templates-$(shell date "+%Y%m%d%H%M%S") | ||
|
||
.PHONY: generate-k8s $(ALL) | ||
generate-k8s: $(ALL) | ||
|
||
test: generate-k8s | ||
for FILE in $(shell ls *-kubernetes.yaml); do \ | ||
BEAT=$$(echo $$FILE | cut -d \- -f 1); \ | ||
|
@@ -14,10 +19,64 @@ test: generate-k8s | |
clean: | ||
@for f in $(ALL); do rm -f "$$f-kubernetes.yaml"; done | ||
|
||
$(ALL): | ||
@echo "Generating $@-kubernetes.yaml" | ||
@rm -f $@-kubernetes.yaml | ||
$(ALL): | ||
ifdef WITHOUTCONFIG | ||
@echo "Generating [email protected]" | ||
@rm -f [email protected] | ||
@for f in $(shell ls $@/*.yaml | grep -v daemonset-configmap); do \ | ||
sed "s/%VERSION%/VERSION/g" $$f >> [email protected]; \ | ||
echo --- >> [email protected]; \ | ||
done | ||
else | ||
@echo "Generating [email protected]" | ||
@rm -f [email protected] | ||
@for f in $(shell ls $@/*.yaml); do \ | ||
sed "s/%VERSION%/${BEAT_VERSION}/g" $$f >> [email protected]; \ | ||
echo --- >> [email protected]; \ | ||
done | ||
done | ||
endif | ||
|
||
CHDIR_SHELL := $(SHELL) | ||
define chdir | ||
$(eval _D=$(firstword $(1) $(@D))) | ||
$(info $(MAKE): cd $(_D)) $(eval SHELL = cd $(_D); $(CHDIR_SHELL)) | ||
endef | ||
|
||
## ci-clone-kibana-repository : Clone Kibana Repository and copy new files for the PR | ||
.PHONY: ci-clone-kibana-repository | ||
ci-clone-kibana-repository: | ||
git clone [email protected]:elastic/kibana.git | ||
cp $(FILE_REPO) $(ELASTIC_AGENT_REPO)/$(ELASTIC_AGENT_REPO_PATH) | ||
|
||
## ci-create-kubernetes-templates-pull-request : Create the pull request for the kubernetes templates | ||
.PHONY: ci-create-kubernetes-templates-pull-request | ||
ci-create-kubernetes-templates-pull-request: | ||
HASDIFF=$$(git status | grep $(FILE_REPO) | wc -l); \ | ||
if [ $${HASDIFF} -ne 1 ]; \ | ||
then \ | ||
echo "No differences found with kibana git repository" && \ | ||
exit 1; \ | ||
fi | ||
echo "INFO: Create branch to update k8s templates" | ||
git checkout -b $(ELASTIC_AGENT_BRANCH) | ||
echo "INFO: add files if any" | ||
git add $(ELASTIC_AGENT_REPO_PATH)$(FILE_REPO) | ||
echo "INFO: commit changes if any" | ||
git diff --staged --quiet || git commit -m "[Automated PR] Publish kubernetes templates for elastic-agent" | ||
echo "INFO: show remote details" | ||
git remote -v | ||
ifeq ($(DRY_RUN),TRUE) | ||
echo "INFO: skip pushing branch" | ||
else | ||
echo "INFO: push branch" | ||
@git push --set-upstream origin $(ELASTIC_AGENT_BRANCH) | ||
echo "INFO: create pull request" | ||
@gh pr create \ | ||
--title "Update kubernetes templates for elastic-agent" \ | ||
--body "Automated by ${BUILD_URL}" \ | ||
--label automation \ | ||
--base main \ | ||
--head $(ELASTIC_AGENT_BRANCH) \ | ||
--reviewer elastic/obs-cloudnative-monitoring | ||
endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
#### | ||
# Bash Script that creates the needed https://github.com/elastic/kibana/blob/main/x-pack/plugins/fleet/server/services/elastic_agent_manifest.ts | ||
# The script takes as an argument the path of elastic-agent manifests | ||
# Eg. ./creator_k8s_manifest.sh deploy/kubernetes | ||
#### | ||
|
||
|
||
STANDALONE=elastic-agent-standalone-kubernetes-without-configmap.yaml | ||
MANAGED=elastic-agent-managed-kubernetes-without-configmap.yaml | ||
OUTPUT_FILE=elastic_agent_manifest.ts | ||
|
||
#Check if arguments provided | ||
((!$#)) && echo "No arguments provided!Please provide path of elastic-agent files" && exit 1 | ||
MANIFEST_PATH=$1 | ||
|
||
#Check if file elastic-agent-standalone-kubernetes-without-configmap.yaml exists | ||
if [ ! -f "$MANIFEST_PATH/$STANDALONE" ]; then | ||
echo "$MANIFEST_PATH/$STANDALONE does not exists" | ||
exit 1 | ||
fi | ||
|
||
#Check if file elastic-agent-managed-kubernetes-without-configmap.yaml exists | ||
if [ ! -f "$MANIFEST_PATH/$MANAGED" ]; then | ||
echo "$MANIFEST_PATH/$MANAGED does not exists" | ||
exit 1 | ||
fi | ||
|
||
#Start creation of output file | ||
cat << EOF > $OUTPUT_FILE | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
export const elasticAgentStandaloneManifest = \`--- | ||
EOF | ||
|
||
cat $MANIFEST_PATH/$STANDALONE >> $OUTPUT_FILE | ||
echo "\`;" >> $OUTPUT_FILE | ||
|
||
cat << EOF >> $OUTPUT_FILE | ||
export const elasticAgentManagedManifest = \`--- | ||
EOF | ||
|
||
cat $MANIFEST_PATH/$MANAGED >> $OUTPUT_FILE | ||
echo -n "\`;" >> $OUTPUT_FILE | ||
|
||
#Replacing all occurencies of elastic-agent-standalone | ||
sed -i -e 's/elastic-agent-standalone/elastic-agent/g' $OUTPUT_FILE | ||
|
||
#Remove ES_HOST entry from file | ||
sed -i -e '/# The Elasticsearch host to communicate with/d' $OUTPUT_FILE | ||
sed -i -e '/ES_HOST/d' $OUTPUT_FILE | ||
sed -i -e '/value: ""/d' $OUTPUT_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
deploy/kubernetes/elastic-agent-standalone/elastic-agent-standalone-daemonset-configmap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters