Skip to content

Commit

Permalink
Prepare OCP cluster deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianriobo committed May 24, 2021
1 parent cedc043 commit 4f2ebd4
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VERSION ?= 0.0.1
CONTAINER_MANAGER ?= podman
# Image URL to use all building/pushing image targets
IMG ?= quay.io/ariobolo/qe-eventmanager:v${VERSION}
IMG ?= quay.io/ariobolo/qe-eventmanager:${VERSION}

# Go and compilation related variables
GOPATH ?= $(shell go env GOPATH)
Expand Down
6 changes: 3 additions & 3 deletions cmd/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const (
certificateFile string = "certificate-file"
privateKeyFile string = "private-key-file"
caCertsFile string = "ca-certs"
kubeconfigPath string = "kubeconfigPath"
kubeconfig string = "kubeconfig"
)

func init() {
Expand All @@ -25,7 +25,7 @@ func init() {
flagSet.StringP(certificateFile, "", "", "certificate file for client auth")
flagSet.StringP(privateKeyFile, "", "", "key file for client auth")
flagSet.StringP(caCertsFile, "", "", "root ca for messageing server auth")
flagSet.StringP(kubeconfigPath, "k", "", "kubeconfig file path")
flagSet.StringP(kubeconfig, "k", "", "kubeconfig file path")
startCmd.Flags().AddFlagSet(flagSet)
}

Expand All @@ -47,6 +47,6 @@ func runStart() {
viper.GetString(certificateFile),
viper.GetString(privateKeyFile),
viper.GetString(caCertsFile),
viper.GetString(kubeconfigPath),
viper.GetString(kubeconfig),
strings.Split(viper.GetString(brokers), ","))
}
15 changes: 11 additions & 4 deletions images/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ FROM registry.access.redhat.com/ubi8/ubi-minimal

LABEL MAINTAINER "Adrian Riobo" "<[email protected]>"

WORKDIR /
COPY --from=builder /workspace/out/qe-eventmanager .
#USER 65532:65532
COPY --from=builder /workspace/out/qe-eventmanager /workspace/images/builder/entrypoint.sh /usr/local/bin/

ENTRYPOINT ["/qe-eventmanager"]
ENTRYPOINT entrypoint.sh



# "start",
# "-b", "messaging-devops-broker02.web.stage.ext.phx2.redhat.com:61612",
# "--ca-certs", "/etc/pki/ca-trust/source/anchors/2015-RH-IT-Root-CA.pem",
# "--certificate-file", "/home/ariobolo/02OFFTOPIC/umb-certificates/psi-crcqe-openstack.crt",
# "--private-key-file", "/home/ariobolo/02OFFTOPIC/umb-certificates/psi-crcqe-openstack.key",
# "-k", "/home/ariobolo/02OFFTOPIC/umb-certificates/config"]
46 changes: 46 additions & 0 deletions images/builder/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

VALID_CONFIG=true
# Check required ENVs
if [ -z "${BROKERS}" ]; then
echo "BROKERS ENV is required"
VALID_CONFIG=false
fi

if [ -z "${CA}" ]; then
echo "CA ENV is required"
VALID_CONFIG=false
fi

if [ -z "${CERTIFICATE}" ]; then
echo "CERTIFICATE ENV is required"
VALID_CONFIG=false
fi

if [ -z "${KEY}" ]; then
echo "KEY ENV is required"
VALID_CONFIG=false
fi

if [ "${VALID_CONFIG}" = false ]; then
echo "Add the required ENVs"
exit 1
fi

# Run qe-eventmanager
if [ -z "${KUBECONFIG}" ]; then
# Inside the cluster por running as SA with permissions
qe-eventmanager start \
--brokers "${BROKERS}" \
--ca-certs "${CA}" \
--certificate-file "${CERTIFICATE}" \
--private-key-file "${KEY}" \
else
# OCP Cluster access based on kubeconfig file
qe-eventmanager start \
--brokers "${BROKERS}" \
--ca-certs "${CA}" \
--certificate-file "${CERTIFICATE}" \
--private-key-file "${KEY}" \
--kubeconfig "${KUBECONFIG}"
fi
6 changes: 6 additions & 0 deletions manifests/create-secret.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

oc create secret generic qe-eventmanager-config \
--from-file=ca=ca.crt \
--from-file=certificate=user.crt \
--from-file=key=user.key
33 changes: 33 additions & 0 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: qe-eventmanager
labels:
app: qe-eventmanager
spec:
replicas: 1
selector:
matchLabels:
app: qe-eventmanager
template:
metadata:
labels:
app: qe-eventmanager
spec:
containers:
- name: qe-eventmanager
image: quay.io/ariobolo/qe-eventmanager:0.0.1
volumeMounts:
- mountPath: /var/run/secrets/tokens
name: vault-token
serviceAccountName: pipeline-runner
volumes:
- name: vault-token
projected:
sources:
- serviceAccountToken:
path: vault-token
expirationSeconds: 7200
audience: vault

35 changes: 35 additions & 0 deletions manifests/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pipeline-runner
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/part-of: qe-eventmanager
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pipeline-runner
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/part-of: qe-eventmanager
rules:
- apiGroups: ["tekton.dev"]
resources: ["tasks", "taskruns", "pipelines", "pipelineruns", "pipelineresources", "conditions"]
verbs: ["get", "list", "create", "update", "delete", "patch", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pipeline-runner
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/part-of: qe-eventmanager
subjects:
- kind: ServiceAccount
name: pipeline-runner
roleRef:
kind: Role
name: pipeline-runner
apiGroup: rbac.authorization.k8s.io
4 changes: 3 additions & 1 deletion pkg/crc/pipelines/contants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

const (
crcNamespace string = "codeready-container"
crcNamespace string = "codeready-container"
pipelinesDashboardBaseUrl string = "https://tekton-dashboard-openshift-pipelines.apps.ocp4.prod.psi.redhat.com"
pipelinesDashboardUrlFormat string = "%s/#/namespaces/%s/pipelineruns/%s"
)

var (
Expand Down
12 changes: 9 additions & 3 deletions pkg/crc/pipelines/pipelines.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package pipelines

import (
"fmt"

"github.com/adrianriobo/qe-eventmanager/pkg/services/ci/pipelines"

v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
Expand All @@ -15,17 +17,17 @@ const (
correlationParamName string = "correlation"
)

func RunInteropOCP(ocpVersion, correlation string) (*v1beta1.PipelineRunStatus, error) {
func RunInteropOCP(ocpVersion, correlation string) (string, string, *v1beta1.PipelineRunStatus, error) {
pipelinerun, err := pipelines.CreatePipelinerun(crcNamespace, getSpecInteropOCP(ocpVersion, correlation))
if err != nil {
return nil, err
return "", "", nil, err
}
status := make(chan *v1beta1.PipelineRunStatus)
informerStopper := make(chan struct{})
defer close(status)
defer close(informerStopper)
go pipelines.AddInformer(crcNamespace, pipelinerun.GetName(), status, informerStopper)
return <-status, nil
return pipelinerun.GetName(), correlation, <-status, nil
}

func getSpecInteropOCP(ocpVersion, correlation string) *v1beta1.PipelineRun {
Expand All @@ -41,3 +43,7 @@ func getSpecInteropOCP(ocpVersion, correlation string) *v1beta1.PipelineRun {
Workspaces: []v1beta1.WorkspaceBinding{crcWorkspace}},
}
}

func GetPipelinerunDashboardUrl(pipelinerunName string) string {
return fmt.Sprintf(pipelinesDashboardUrlFormat, pipelinesDashboardBaseUrl, crcNamespace, pipelinerunName)
}
65 changes: 43 additions & 22 deletions pkg/event/interop/ocp/event.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ocp

import (
"fmt"
"time"

"github.com/mitchellh/mapstructure"

"github.com/adrianriobo/qe-eventmanager/pkg/crc/pipelines"
Expand All @@ -10,8 +13,8 @@ import (
)

const (
buildComplete string = "VirtualTopic.qe.ci.product-scenario.ascerra.build.complete"
testComplete string = "VirtualTopic.qe.ci.product-scenario.ascerra.test.complete"
topicBuildComplete string = "VirtualTopic.qe.ci.product-scenario.ascerra.build.complete"
topicTestComplete string = "VirtualTopic.qe.ci.product-scenario.ascerra.test.complete"
// testError string = "VirtualTopic.qe.ci.product-scenario.ascerra.test.error"
)

Expand All @@ -23,7 +26,7 @@ func New() ProductScenarioBuild {
}

func (p ProductScenarioBuild) GetDestination() string {
return buildComplete
return topicBuildComplete
}
func (p ProductScenarioBuild) Handler(event interface{}) error {
var data BuildComplete
Expand All @@ -34,32 +37,50 @@ func (p ProductScenarioBuild) Handler(event interface{}) error {
// Business Logic
for _, product := range data.Artifact.Products {
if product.Name == "openshift" {
_, err := pipelines.RunInteropOCP(product.Id, util.GenerateCorrelation())
name, correlation, _, err := pipelines.RunInteropOCP(product.Id, util.GenerateCorrelation())
if err != nil {
logging.Error(err)
}
// We will take info from status to send back the results
var response TestComplete
mockResponse(&data, &response)

return umb.Send(testComplete, response)
response := buildResponse(name, correlation, &data)
return umb.Send(topicTestComplete, response)
}
}
return nil
}

func mockResponse(source *BuildComplete, response *TestComplete) {
response.Artifact = source.Artifact
response.Run = Run{
URL: "https://crcqe-jenkins-csb-codeready.cloud.paas.psi.redhat.com/view/qe-bundle-baremetal/job/qe/job/bundle_baremetal_macos14-brno/284",
Log: "https://crcqe-jenkins-csb-codeready.cloud.paas.psi.redhat.com/view/qe-bundle-baremetal/job/qe/job/bundle_baremetal_macos14-brno/284/console"}
response.Test = Test{
Category: "interoperability",
Namespace: "interop",
TestType: "product-scenario",
Result: "passed",
Runtime: "1800",
XunitUrls: []string{
"https://crcqe-jenkins-csb-codeready.cloud.paas.psi.redhat.com/view/qe-bundle-baremetal/job/qe/job/bundle_baremetal_macos14-brno/284/console",
"https://crcqe-jenkins-csb-codeready.cloud.paas.psi.redhat.com/view/qe-bundle-baremetal/job/qe/job/bundle_baremetal_macos14-brno/284/console"}}
func buildResponse(name, correlation string, source *BuildComplete) *TestComplete {
return &TestComplete{
Artifact: source.Artifact,
Run: Run{
URL: pipelines.GetPipelinerunDashboardUrl(name),
Log: pipelines.GetPipelinerunDashboardUrl(name)},
Test: Test{
Category: "interoperability",
Namespace: "interop",
TestType: "product-scenario",
Result: "passed",
Runtime: "1800",
XunitUrls: xunitFilesUrls(correlation)},
}
}

func xunitFilesUrls(correlation string) []string {
var xunitUrls []string
servers := []string{"fedora33", "macos14-brno", "macos15-brno",
"rhel79", "rhel8-brno", "rhel83", "windows10-brno"}
files := []string{"basic.xml", "config.xml", "story_health.xml",
"story_marketplace.xml", "story_registry.xml", "cert_rotation.xml",
"proxy.xml", "integration.xml"}
datalakeUrl := "http://10.0.110.220:9000/logs"
t := time.Now().Local()
logsDate := fmt.Sprint(t.Format("20060102"))
for _, server := range servers {
for _, file := range files {
url := fmt.Sprintf("%s/%s/%s/%s/%s",
datalakeUrl, logsDate, correlation, server, file)
xunitUrls = append(xunitUrls, url)
}
}
return xunitUrls
}
2 changes: 1 addition & 1 deletion pkg/event/event.go → pkg/manager/event.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package event
package manager

type Event interface {
GetDestination() error
Expand Down

0 comments on commit 4f2ebd4

Please sign in to comment.