Skip to content

Commit

Permalink
Merge pull request #10 from adrianriobo/0.0.1
Browse files Browse the repository at this point in the history
Enable container on OCP
  • Loading branch information
adrianriobo authored Jul 29, 2021
2 parents a08fc98 + a25409c commit 05bb997
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out/
run.sh
.vscode
manifests/config.yaml
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# qe-eventmanager
Sample app for handling qe events

[![Container Repository on Quay](https://quay.io/repository/ariobolo/qe-eventmanager/status "Container Repository on Quay")](https://quay.io/repository/ariobolo/qe-eventmanager)

# overview

UMB integration with qe platform

![Overview](docs/diagrams/overview.jpg?raw=true)

# Deploy

```bash
# Create config
manifest/create-config.sh $CA_FILE_PATH $CERTIFICATE_FILE_PATH $KEY_FILE_PATH $BROKERS

# Deploy resources
oc apply -f manifest/config.yaml
oc apply -f manifest/rbac.yaml
oc apply -f manifest/deployment.yaml
```
1 change: 1 addition & 0 deletions docs/diagrams/next.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Electron" modified="2021-05-27T13:26:32.004Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/13.7.9 Chrome/85.0.4183.121 Electron/10.1.3 Safari/537.36" etag="EDz0NQuypPi37l_St9Zg" version="13.7.9" type="device"><diagram id="v7w19SHdzy4iny7pc1Io" name="Page-1">7VzdcqM2GH2azLQXmwEkQFxusrvdXmQm022n2asOBtnWLAaPkDd2n77CFhgkOZYdAYndK1tCYDjf0fl+JHwD7hfr32i8nD8UKc5uPCdd34BPN57nIhDyj6pns+tByNl1zChJxaB9xzfyLxad9bAVSXHZGciKImNk2e1MijzHCev0xZQWz91h0yLr/uoynmGl41sSZ2rv3yRlc/EUvrPv/4rJbF7/suuII4u4Hiw6ynmcFs+tLvD5BtzTom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4kVRN8QL4ADsO3e+2GQtepeshbLjNmatI7EWDsxadaVHrEioFQyrcdgwK0CBLArjB2LqEtCrZAJ1ZAK6L8vEgUTwWB54uu10gmRRJoCpSvhXHYwdTgSt64haqHsFrf02qc0Y7d46DuqyGgThsUCvar2pAodnWuG47izj1ApHILtZx5NmQR8VjsNV1e1yzfsvc0ShBKtuwWBY92qwtdBUh05K/w6Ezs5pnnXYFNEzrmmgMdUGyWoji4Sp2iC5nmqYIp5cT3WANC/czi7ZfuSm/s32lpbtqvDBpZwLCOg93RLwoIoDDLbZnhf5mMbyr1Ic483Rw4Y3wNHTYBjF8aVtr82LAacqTiALgUzDntN7oFZRxfr5h/02q/cfhyDngL3GU4XTqoFit42+dh2EoJvYRFFkIbGxGmu88Xodilw7ExqhoDuhIRh2QhvszB4yvj1WGh41ma7F97i3GXW/QChlUWcXk5FclZZZbim+RfI+MWeI8FYtnO7CW5JPC3qh9WrtDrxhHZnFwt7lC05g6g1HTahDKaGG55bvkKRczT6XvhPq+rWFfhVHrd+dTf1TMrtRMzRznxmMSeFAztDOpbByIUMK2yJZPRWlTf6VOxPb+at7ydPKdrj6COJF5brySblsLH9ZTk/34sWwTg+OVNMZd+abOi84am1GnrBA3jFx7swH8tu0fc98722QzGAxv7XI6nrdWkQQHt1Np6tFWOQtNPVYo1YgZLb5MttMaQulRYxGGW0vmUqxnS//04c83jttvO+/brzbHd9PCAjV+mnJuDeu3n3xnBRPSU4YqfasOwuczOOclAtlEl/Mn0HI7wn4usWXSDOHznj/jjf3/1KzM+f+v37A5/8A</diagram></mxfile>
Binary file added docs/diagrams/next.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions images/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build the manager binary
FROM registry.access.redhat.com/ubi8/go-toolset:1.14.12 as builder

USER root
WORKDIR /workspace
COPY . .
RUN make build
Expand All @@ -12,12 +13,3 @@ LABEL MAINTAINER "Adrian Riobo" "<[email protected]>"
COPY --from=builder /workspace/out/qe-eventmanager /workspace/images/builder/entrypoint.sh /usr/local/bin/

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"]
24 changes: 11 additions & 13 deletions images/builder/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ 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}" \
exec 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}"
exec qe-eventmanager start \
--brokers "${BROKERS}" \
--ca-certs "${CA}" \
--certificate-file "${CERTIFICATE}" \
--private-key-file "${KEY}" \
--kubeconfig "${KUBECONFIG}"
fi
30 changes: 30 additions & 0 deletions manifests/create-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Usage create-config.sh $CA_FILE_PATH $CERTIFICATE_FILE_PATH $KEY_FILE_PATH $BROKERS

ca=$(cat $1 | base64 -w0)
certificate=$(cat $2 | base64 -w0)
key=$(cat $3 | base64 -w0)
brokers=$(echo -n $4 | base64 -w0)


if [ "${DEBUG:-}" = "true" ]; then
set -xuo
fi

set -e pipefail

# Create file
cat <<EOF > config.yaml
---
apiVersion: v1
kind: Secret
metadata:
name: qe-eventmanager-config
type: Opaque
data:
ca: ${ca}
certificate: ${certificate}
key: ${key}
brokers: ${brokers}
EOF
6 changes: 0 additions & 6 deletions manifests/create-secret.sh

This file was deleted.

36 changes: 25 additions & 11 deletions manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ spec:
containers:
- name: qe-eventmanager
image: quay.io/ariobolo/qe-eventmanager:0.0.1
env:
- name: BROKERS
valueFrom:
secretKeyRef:
name: qe-eventmanager-config
key: brokers
- name: CA
value: /etc/qe-eventmanager/ca.crt
- name: CERTIFICATE
value: /etc/qe-eventmanager/sa.crt
- name: KEY
value: /etc/qe-eventmanager/sa.key
volumeMounts:
- mountPath: /var/run/secrets/tokens
name: vault-token
serviceAccountName: pipeline-runner
- mountPath: /etc/qe-eventmanager/
name: qe-eventmanager-config
serviceAccountName: qe-eventmanager
volumes:
- name: vault-token
projected:
sources:
- serviceAccountToken:
path: vault-token
expirationSeconds: 7200
audience: vault

- name: qe-eventmanager-config
secret:
secretName: qe-eventmanager-config
items:
- key: ca
path: ca.crt
- key: certificate
path: sa.crt
- key: key
path: sa.key
10 changes: 5 additions & 5 deletions manifests/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: pipeline-runner
name: qe-eventmanager
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
name: qe-eventmanager
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/part-of: qe-eventmanager
Expand All @@ -22,14 +22,14 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pipeline-runner
name: qe-eventmanager
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/part-of: qe-eventmanager
subjects:
- kind: ServiceAccount
name: pipeline-runner
name: qe-eventmanager
roleRef:
kind: Role
name: pipeline-runner
name: qe-eventmanager
apiGroup: rbac.authorization.k8s.io
2 changes: 1 addition & 1 deletion pkg/crc/pipelines/contants.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ var (
}

defaultTimeout v1.Duration = v1.Duration{
Duration: 5 * time.Hour,
Duration: 8 * time.Hour,
}
)
12 changes: 8 additions & 4 deletions pkg/crc/pipelines/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ const (

ocpVersionParamName string = "ocp-version"
correlationParamName string = "correlation"
serversidsParamName string = "servers-ids"
platformsParamName string = "platforms"
)

func RunInteropOCP(ocpVersion, correlation string) (string, string, *v1beta1.PipelineRunStatus, error) {
pipelinerun, err := pipelines.CreatePipelinerun(crcNamespace, getSpecInteropOCP(ocpVersion, correlation))
func RunInteropOCP(ocpVersion, correlation, serversids, platforms string) (string, string, *v1beta1.PipelineRunStatus, error) {
pipelinerun, err := pipelines.CreatePipelinerun(crcNamespace, getSpecInteropOCP(ocpVersion, correlation, serversids, platforms))
if err != nil {
return "", "", nil, err
}
Expand All @@ -30,15 +32,17 @@ func RunInteropOCP(ocpVersion, correlation string) (string, string, *v1beta1.Pip
return pipelinerun.GetName(), correlation, <-status, nil
}

func getSpecInteropOCP(ocpVersion, correlation string) *v1beta1.PipelineRun {
func getSpecInteropOCP(ocpVersion, correlation, serversids, platforms string) *v1beta1.PipelineRun {
return &v1beta1.PipelineRun{
TypeMeta: v1.TypeMeta{},
ObjectMeta: v1.ObjectMeta{GenerateName: pipelineRunName, Namespace: crcNamespace},
Spec: v1beta1.PipelineRunSpec{
PipelineRef: &v1beta1.PipelineRef{Name: pipelineRefName},
Params: []v1beta1.Param{
{Name: ocpVersionParamName, Value: *v1beta1.NewArrayOrString(ocpVersion)},
{Name: correlationParamName, Value: *v1beta1.NewArrayOrString(correlation)}},
{Name: correlationParamName, Value: *v1beta1.NewArrayOrString(correlation)},
{Name: serversidsParamName, Value: *v1beta1.NewArrayOrString(serversids)},
{Name: platformsParamName, Value: *v1beta1.NewArrayOrString(platforms)}},
Timeout: &defaultTimeout,
Workspaces: []v1beta1.WorkspaceBinding{crcWorkspace}},
}
Expand Down
45 changes: 31 additions & 14 deletions pkg/event/interop/ocp/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocp

import (
"fmt"
"strings"
"time"

"github.com/mitchellh/mapstructure"
Expand All @@ -13,11 +14,19 @@ import (
)

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

var (
serversids []string = []string{"macos14-brno", "macos15-brno", "windows10-brno", "rhel8-brno"}
platforms []string = []string{"fedora33", "rhel79", "rhel83"}
files []string = []string{"basic.xml", "config.xml", "story_health.xml",
"story_marketplace.xml", "story_registry.xml", "cert_rotation.xml",
"proxy.xml", "integration.xml"}
)

type ProductScenarioBuild struct {
}

Expand All @@ -35,17 +44,29 @@ func (p ProductScenarioBuild) Handler(event interface{}) error {
return err
}
// Business Logic
var openshiftVersion string = ""
var codereadyContainersMessage bool = false
for _, product := range data.Artifact.Products {
if product.Name == "openshift" {
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
response := buildResponse(name, correlation, &data)
return umb.Send(topicTestComplete, response)
openshiftVersion = product.Id
}
if product.Name == "codeready_containers" {
codereadyContainersMessage = true
}
}
// Filtering this will be improved in future versions
if len(openshiftVersion) > 0 && codereadyContainersMessage {
name, correlation, _, err :=
pipelines.RunInteropOCP(openshiftVersion, util.GenerateCorrelation(),
strings.Join(serversids[:], ","),
strings.Join(platforms[:], ","))
if err != nil {
logging.Error(err)
}
// We will take info from status to send back the results
response := buildResponse(name, correlation, &data)
return umb.Send(topicTestComplete, response)
}
return nil
}

Expand All @@ -67,14 +88,10 @@ func buildResponse(name, correlation string, source *BuildComplete) *TestComplet

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"))
servers := append(serversids, platforms...)
for _, server := range servers {
for _, file := range files {
url := fmt.Sprintf("%s/%s/%s/%s/%s",
Expand Down
6 changes: 5 additions & 1 deletion pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manager
import (
"os"
"os/signal"
"syscall"

eventInteropOCP "github.com/adrianriobo/qe-eventmanager/pkg/event/interop/ocp"
"github.com/adrianriobo/qe-eventmanager/pkg/services/ci/pipelines"
Expand Down Expand Up @@ -46,7 +47,10 @@ func handleEvents() error {

func waitForStop() {
s := make(chan os.Signal, 1)
signal.Notify(s, os.Interrupt)
signal.Notify(s,
os.Interrupt,
syscall.SIGTERM,
syscall.SIGQUIT)
<-s
}

Expand Down
Loading

0 comments on commit 05bb997

Please sign in to comment.