Skip to content

Commit

Permalink
Merge branch 'kubeshop:develop' into djmeter-support
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshwani authored Sep 11, 2023
2 parents 69c5b29 + aac7795 commit afccd30
Show file tree
Hide file tree
Showing 44 changed files with 592 additions and 174 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.

name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '35 11 * * 1'
push:
branches: [ "develop", "main" ]

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
# Uncomment the permissions below if installing in a private repository.
# contents: read
# actions: read

steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
with:
results_file: results.sarif
results_format: sarif
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
# - you want to enable the Branch-Protection check on a *public* repository, or
# - you are installing Scorecard on a *private* repository
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
# repo_token: ${{ secrets.SCORECARD_TOKEN }}

# Public repositories:
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories:
# - `publish_results` will always be set to `false`, regardless
# of the value entered here.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4
with:
sarif_file: results.sarif
45 changes: 44 additions & 1 deletion api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3188,6 +3188,32 @@ paths:
items:
$ref: "#/components/schemas/Problem"

/secrets:
get:
tags:
- secrets
- api
summary: "List secrets"
description: "List secrets available in cluster"
operationId: listSecrets
responses:
200:
description: "successful operation"
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Secret"
502:
description: "problem with communicating with kubernetes cluster or git server"
content:
application/problem+json:
schema:
type: array
items:
$ref: "#/components/schemas/Problem"

components:
schemas:
ExecutionsMetrics:
Expand Down Expand Up @@ -5152,7 +5178,7 @@ components:
description: name of the template resource
headers:
type: object
description: "webhook headers"
description: "webhook headers (golang template supported)"
additionalProperties:
type: string
example:
Expand Down Expand Up @@ -5690,6 +5716,23 @@ components:
allOf:
- $ref: "#/components/schemas/Template"

Secret:
description: Secret with keys
type: object
required:
- name
properties:
name:
type: string
description: secret name
example: "git-secret"
keys:
type: array
description: secret keys
items:
type: string
example: ["key1", "key2", "key3"]

#
# Errors
#
Expand Down
2 changes: 2 additions & 0 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func main() {
configMapConfig,
configMapClient,
testsuiteExecutionsClient,
eventBus,
)

slackLoader, err := newSlackLoader(cfg, envs)
Expand Down Expand Up @@ -431,6 +432,7 @@ func main() {
cfg.TestkubeDashboardURI,
cfg.TestkubeHelmchartVersion,
mode,
eventBus,
)

if mode == common.ModeAgent {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/common/cloudcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func UiContextHeader(cmd *cobra.Command, cfg config.Data) {
header += ui.DarkGray("Env: ") + ui.White(envName)
} else {
header += ui.DarkGray("Context: ") + ui.White(cfg.ContextType) + ui.DarkGray(" ("+Version+")") + separator
header += ui.DarkGray("Namespace: ") + ui.White(cfg.Namespace)
header += ui.DarkGray("Namespace: ") + ui.White(cmd.Flag("namespace").Value.String())
}

fmt.Println(header)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/templates/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewCreateTemplateOptionsFromFlags(cmd *cobra.Command) (options apiv1.Create
if templateType != testkube.JOB_TemplateType && templateType != testkube.CRONJOB_TemplateType &&
templateType != testkube.SCRAPER_TemplateType && templateType != testkube.PVC_TemplateType &&
templateType != testkube.WEBHOOK_TemplateType {
ui.Failf("invalid template type: %s. use one of job|container|cronnjob|scraper|pvc|webhook", templateType)
ui.Failf("invalid template type: %s. use one of job|container|cronjob|scraper|pvc|webhook", templateType)
}

body := cmd.Flag("body").Value.String()
Expand Down Expand Up @@ -75,7 +75,7 @@ func NewUpdateTemplateOptionsFromFlags(cmd *cobra.Command) (options apiv1.Update
if templateType != testkube.JOB_TemplateType && templateType != testkube.CRONJOB_TemplateType &&
templateType != testkube.SCRAPER_TemplateType && templateType != testkube.PVC_TemplateType &&
templateType != testkube.WEBHOOK_TemplateType {
ui.Failf("invalid template type: %s. use one of job|container|cronnjob|scraper|pvc|webhook", templateType)
ui.Failf("invalid template type: %s. use one of job|container|cronjob|scraper|pvc|webhook", templateType)
}
options.Type_ = &templateType
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/kubectl-testkube/commands/templates/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func NewCreateTemplateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "template",
Aliases: []string{"tp"},
Short: "Create new Template",
Long: `Create new Template Custom Resource`,
Short: "Create a new Template.",
Long: `Create a new Template Custom Resource.`,
Run: func(cmd *cobra.Command, args []string) {
crdOnly, err := strconv.ParseBool(cmd.Flag("crd-only").Value.String())
ui.ExitOnError("parsing flag value", err)
Expand Down Expand Up @@ -67,7 +67,7 @@ func NewCreateTemplateCmd() *cobra.Command {
}

cmd.Flags().StringVarP(&name, "name", "n", "", "unique template name - mandatory")
cmd.Flags().StringVarP(&templateType, "template-type", "", "", "template type one of job|container|cronnjob|scraper|pvc|webhook")
cmd.Flags().StringVarP(&templateType, "template-type", "", "", "template type one of job|container|cronjob|scraper|pvc|webhook")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&body, "body", "", "", "a path to template file to use as template body")

Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/templates/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func NewDeleteTemplateCmd() *cobra.Command {

Use: "template <templateName>",
Aliases: []string{"tp"},
Short: "Delete template",
Long: `Delete template, pass template name which should be deleted`,
Short: "Delete a template.",
Long: `Delete a template and pass the template name to be deleted.`,
Run: func(cmd *cobra.Command, args []string) {
client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/templates/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func NewGetTemplateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "template <templateName>",
Aliases: []string{"templates", "tp"},
Short: "Get template details",
Long: `Get template, you can change output format, to get single details pass name as first arg`,
Short: "Get template details.",
Long: `Get template allows you to change the output format. To get single details, pass the template name as the first argument.`,
Run: func(cmd *cobra.Command, args []string) {
client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/templates/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func UpdateTemplateCmd() *cobra.Command {
Use: "template",
Aliases: []string{"templates", "tp"},
Short: "Update Template",
Long: `Update Template Custom Resource`,
Long: `Update Template Custom Resource.`,
Run: func(cmd *cobra.Command, args []string) {
if name == "" {
ui.Failf("pass valid name (in '--name' flag)")
Expand All @@ -44,7 +44,7 @@ func UpdateTemplateCmd() *cobra.Command {
}

cmd.Flags().StringVarP(&name, "name", "n", "", "unique template name - mandatory")
cmd.Flags().StringVarP(&templateType, "template-type", "", "", "template type one of job|container|cronnjob|scraper|pvc|webhook")
cmd.Flags().StringVarP(&templateType, "template-type", "", "", "template type one of job|container|cronjob|scraper|pvc|webhook")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&body, "body", "", "", "a path to template file to use as template body")

Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/testsources/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewCreateTestSourceCmd() *cobra.Command {
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&sourceType, "source-type", "", "", "source type of test one of string|file-uri|git")
cmd.Flags().StringVarP(&file, "file", "f", "", "source file - will be read from stdin if not specified")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called to get test content")
cmd.Flags().StringVarP(&gitUri, "git-uri", "", "", "Git repository uri")
cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter")
cmd.Flags().StringVarP(&gitCommit, "git-commit", "", "", "if uri is git repository we can use commit id (sha) parameter")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kubectl-testkube/commands/testsources/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func UpdateTestSourceCmd() *cobra.Command {
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&sourceType, "source-type", "", "", "source type of test one of string|file-uri|git")
cmd.Flags().StringVarP(&file, "file", "f", "", "source file - will be read from stdin if not specified")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called to get test content")
cmd.Flags().StringVarP(&gitUri, "git-uri", "", "", "Git repository uri")
cmd.Flags().StringVarP(&gitBranch, "git-branch", "", "", "if uri is git repository we can set additional branch parameter")
cmd.Flags().StringVarP(&gitCommit, "git-commit", "", "", "if uri is git repository we can use commit id (sha) parameter")
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/webhooks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ func NewCreateWebhookCmd() *cobra.Command {

cmd.Flags().StringVarP(&name, "name", "n", "", "unique webhook name - mandatory")
cmd.Flags().StringArrayVarP(&events, "events", "e", []string{}, "event types handled by webhook e.g. start-test|end-test")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs (golang template supported)")
cmd.Flags().StringVarP(&selector, "selector", "", "", "expression to select tests and test suites for webhook events: --selector app=backend")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&payloadObjectField, "payload-field", "", "", "field to use for notification object payload")
cmd.Flags().StringVarP(&payloadTemplate, "payload-template", "", "", "if webhook needs to send a custom notification, then a path to template file should be provided")
cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair: --header Content-Type=application/xml")
cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair (golang template supported): --header Content-Type=application/xml")
cmd.Flags().StringVar(&payloadTemplateReference, "payload-template-reference", "", "reference to payload template to use for the webhook")

return cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/kubectl-testkube/commands/webhooks/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ func UpdateWebhookCmd() *cobra.Command {

cmd.Flags().StringVarP(&name, "name", "n", "", "unique webhook name - mandatory")
cmd.Flags().StringArrayVarP(&events, "events", "e", []string{}, "event types handled by webhook e.g. start-test|end-test")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs")
cmd.Flags().StringVarP(&uri, "uri", "u", "", "URI which should be called when given event occurs (golang template supported)")
cmd.Flags().StringVarP(&selector, "selector", "", "", "expression to select tests and test suites for webhook events: --selector app=backend")
cmd.Flags().StringToStringVarP(&labels, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().StringVarP(&payloadObjectField, "payload-field", "", "", "field to use for notification object payload")
cmd.Flags().StringVarP(&payloadTemplate, "payload-template", "", "", "if webhook needs to send a custom notification, then a path to template file should be provided")
cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair: --header Content-Type=application/xml")
cmd.Flags().StringToStringVarP(&headers, "header", "", nil, "webhook header value pair (golang template supported): --header Content-Type=application/xml")
cmd.Flags().StringVar(&payloadTemplateReference, "payload-template-reference", "", "reference to payload template to use for the webhook")

return cmd
Expand Down
3 changes: 1 addition & 2 deletions cmd/kubectl-testkube/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -10,7 +9,7 @@ import (

func TestSave(t *testing.T) {
// override default directory
dir, err := ioutil.TempDir("", "test-config-save")
dir, err := os.MkdirTemp("", "test-config-save")
assert.NoError(t, err)
defaultDirectory = dir

Expand Down
19 changes: 19 additions & 0 deletions contrib/docker/jmeter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Variables
DOCKER_REPOSITORY = kubeshop
DOCKER_IMAGE_NAME = jmeter
DOCKER_TAG = 5.5

# Build the Docker image
.PHONY: build
build:
@echo "Building Docker image..."
@docker buildx build --platform linux/amd64,linux/arm64 -f jmeter5.5.ubi8.8.Dockerfile -t $(DOCKER_REPOSITORY)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) .

.PHONY: push
push: build
@echo "Pushing Docker image..."
@docker buildx build --push --platform linux/amd64,linux/arm64 -f jmeter5.5.ubi8.8.Dockerfile -t $(DOCKER_REPOSITORY)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) .

test: build
@echo "Testing Docker image..."
@docker run --rm -it $(DOCKER_REPOSITORY)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG) --version
25 changes: 25 additions & 0 deletions contrib/docker/jmeter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# JMeter

This repository contains Dockerfiles for JMeter builds which are used by the Testkube JMeter Executor.

Currently supported builds:
* JMeter 5.5 with OpenJDK 17 built on RHEL UBI 8.8 (minimal)

## Development

Use the following `make` targets to build and push the images:

To build the JMeter Docker image use:
```bash
make build
```

To do a quick test run of the JMeter Docker image use:
```bash
make test
```

To push the JMeter Docker image to the registry use:
```bash
make push
```
33 changes: 33 additions & 0 deletions contrib/docker/jmeter/jmeter5.5.ubi8.8.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Use Red Hat's Universal Base Image 8
FROM redhat/ubi8-minimal:8.8

ENV JAVA_VERSION=17
ENV JMETER_VERSION=5.5

# Labels and authorship
LABEL org.opencontainers.image.title="JMeter" \
org.opencontainers.image.description="Red Hat UBI with Java $JAVA_VERSION and JMeter $JMETER_VERSION" \
org.opencontainers.image.version="$JMETER_VERSION" \
org.opencontainers.image.maintainer="[email protected]" \
org.opencontainers.image.vendor="testkube" \
org.opencontainers.image.url="https://cloud.testkube.io" \
org.opencontainers.image.source="https://github.com/kubeshop/testkube/tree/develop/contrib/docker/jmeter"

# Update the system and install required libraries
RUN microdnf update -y && \
microdnf install curl unzip java-$JAVA_VERSION-openjdk tar && \
microdnf clean all

# Install JMeter
RUN curl -L https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-$JMETER_VERSION.tgz | tar xz -C /opt/ && \
mv /opt/apache-jmeter-$JMETER_VERSION /opt/jmeter

# Set JMeter Home and add JMeter bin directory to the PATH
ENV JMETER_HOME /opt/jmeter
ENV PATH $JMETER_HOME/bin:$PATH

# Expose the required JMeter ports
EXPOSE 60000

# Command to run JMeter tests
ENTRYPOINT [ "jmeter" ]
Loading

0 comments on commit afccd30

Please sign in to comment.