Skip to content

Commit

Permalink
wip: convert deployment of grafana to kustomize
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Hiller <[email protected]>
  • Loading branch information
dhiller committed Dec 27, 2024
1 parent 7037fe3 commit 1d7fd1d
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 22 deletions.
3 changes: 1 addition & 2 deletions github/ci/services/common/k8s/pkg/wait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package wait

import (
"context"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -184,7 +183,7 @@ func ForPortOpen(host, port string) error {
for {
select {
case <-timeout:
return errors.New(fmt.Sprintf("Port %s was not open in time", port))
return fmt.Errorf("port %s was not open in time", port)
case <-tick:
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), time.Second)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions github/ci/services/grafana/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace: monitoring

resources:
- manifests/grafana.yaml
9 changes: 3 additions & 6 deletions github/ci/services/grafana/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func TestPrometheusStackDeployment(t *testing.T) {
}

var _ = Describe("grafana deployment", func() {
DescribeTable("should deploy HTTP services",
func(svcPort, labelSelector, expectedContent, urlPath string) {
check.HTTPService(testNamespace, svcPort, labelSelector, expectedContent, urlPath)
},
Entry("grafana service", "3000", "app=grafana", "<title>Grafana</title>", ""),
)
It("should deploy HTTP services", func() {
check.HTTPService(testNamespace, "3000", "app=grafana", "<title>Grafana</title>", "")
})
})
71 changes: 58 additions & 13 deletions github/ci/services/grafana/hack/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
#!/bin/bash
#!/usr/bin/env bash
#
# This file is part of the KubeVirt project
#
# Licensed 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.
#
# Copyright the KubeVirt Authors.
#
#

set -eo pipefail
set -e
set -u
set -o pipefail

main() {
local environment=${1}
set -x

bazelisk run //github/ci/services/grafana:$environment.apply

bazelisk run //github/ci/services/common/k8s/cmd/wait -- -namespace monitoring -selector grafana-deployment -kind deployment

kubectl wait --timeout 60s --for=jsonpath='{.status.stage}'=complete -n monitoring grafana grafana

if [ "$environment" != "testing" ]; then
kubectl apply -n monitoring -f ./github/ci/services/grafana/manifests/ingress.yaml
fi
WORK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BASE_DIR="$(cd "${WORK_DIR}/.." && pwd)"

function usage {
cat <<EOF
usage: $0 [-d] <environment>
EOF
}

main "${@}"
dry_run=false
while getopts "d" opt; do
case "${opt}" in
d )
dry_run="true"
shift
;;
\? )
usage
exit 1
;;
esac
done

environment="${1}"
[ -d "${BASE_DIR}/overlays/${environment}" ] || exit 1

cd "${BASE_DIR}"

if [ "$dry_run" = "true" ]; then
kubectl kustomize "./overlays/${environment}"
exit 0
fi

kubectl apply -k "./overlays/${environment}"

go run ../common/k8s/cmd/wait -namespace monitoring -selector grafana-deployment -kind deployment

kubectl wait --timeout 60s --for=jsonpath='{.status.stage}'=complete -n monitoring grafana grafana
2 changes: 1 addition & 1 deletion github/ci/services/grafana/hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ helm upgrade --namespace monitoring -i grafana-operator oci://ghcr.io/grafana-op

kubectl label -n monitoring svc/grafana-service app=grafana

bazelisk test //github/ci/services/grafana/e2e:go_default_test --test_env=KUBECONFIG=$KUBECONFIG --test_output=all --test_arg=-test.v
env KUBECONFIG=$KUBECONFIG go test -v ./github/ci/services/grafana/e2e/e2e_test.go

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- ../../base
- ./manifests/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- ../../base
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
admin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
client-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
client-secret
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

0 comments on commit 1d7fd1d

Please sign in to comment.