Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/license-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ name: Check Go Dependency Licenses

on:
workflow_call: {}
pull_request:
push:
tags:
- v*
branches:
- main
paths:
- go.mod
- go.sum

pull_request:

permissions:
contents: read

Expand Down
91 changes: 91 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: publish
on:
push:
tags:
- v*
workflow_dispatch:


permissions:
packages: write

env:
OCI_URL: ghcr.io/sap

jobs:
release_tag:
name: Release version
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.PUSH_KEY }}
fetch-tags: true
fetch-depth: 0

- name: Read and validate VERSION
id: version
run: |
VERSION=$(cat VERSION)
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then
echo "Invalid version format in VERSION file: $VERSION"
exit 1
fi
echo "New version: $VERSION"
echo "version=$VERSION" >> $GITHUB_ENV

- name: Skip release if version is a dev version
if: contains(env.version, '-dev')
run: |
echo "Skipping development version release: ${{ env.version }}"
echo "SKIP=true" >> $GITHUB_ENV
exit 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Context for Buildx
id: buildx-context
run: |
docker context create builders

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
timeout-minutes: 5
uses: docker/setup-buildx-action@v2
with:
version: latest

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Build the ${{ github.repository }}
run: |
make reviewable
make build

- name: Build Images
run: |
IMAGE_REGISTRY=ghcr.io/sap/metrics-operator make docker-build

- name: setup OCM
uses: open-component-model/ocm-setup-action@main

- name: Create OCM CTF
run: |
ocm add componentversions --create \
--file ctf component-constructor.yaml \
--settings settings.yaml -- VERSION=${{ env.version }}

- name: Push CTF
run: |
ocm transfer ctf --overwrite ./ctf ${{ env.OCI_URL }}
121 changes: 121 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Versioned Release

on:
push:
branches:
- main

permissions:
contents: write # we need this to be able to push tags

jobs:
release_tag:
name: Release version
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.PUSH_KEY }}
fetch-tags: true
fetch-depth: 0

- name: Read and validate VERSION
id: version
run: |
VERSION=$(cat VERSION)
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-dev)?$ ]]; then
echo "Invalid version format in VERSION file: $VERSION"
exit 1
fi
echo "New version: $VERSION"
echo "version=$VERSION" >> $GITHUB_ENV

- name: Skip release if version is a dev version
if: contains(env.version, '-dev')
run: |
echo "Skipping development version release: ${{ env.version }}"
echo "SKIP=true" >> $GITHUB_ENV
exit 0

- name: Check if VERSION is already tagged
id: check_tag
run: |
if git rev-parse "refs/tags/${{ env.version }}" >/dev/null 2>&1; then
echo "Tag ${{ env.version }} already exists. Skipping release."
echo "SKIP=true" >> $GITHUB_ENV
exit 0
fi
echo "Tag ${{ env.version }} doesn't exists. Proceeding with release."

- name: Create Git tag
if: ${{ env.SKIP != 'true' }}
run: |
AUTHOR_NAME=$(git log -1 --pretty=format:'%an')
AUTHOR_EMAIL=$(git log -1 --pretty=format:'%ae')
echo "Tagging as $AUTHOR_NAME <$AUTHOR_EMAIL>"

echo "AUTHOR_NAME=$AUTHOR_NAME" >> $GITHUB_ENV
echo "AUTHOR_EMAIL=$AUTHOR_EMAIL" >> $GITHUB_ENV

git config user.name "$AUTHOR_NAME"
git config user.email "$AUTHOR_EMAIL"

git tag -a "${{ env.version }}" -m "Release ${{ env.version }}"
git push origin "${{ env.version }}"

- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v5
with:
mode: "PR"
configurationJson: |
{
"template": "#{{CHANGELOG}}",
"pr_template": "- #{{TITLE}}: ##{{NUMBER}}",
"categories": [
{
"title": "## Feature",
"labels": ["feat", "feature"]
},
{
"title": "## Fix",
"labels": ["fix", "bug"]
},
{
"title": "## Other",
"labels": []
}
],
"label_extractor": [
{
"pattern": "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\\([\\w\\-\\.]+\\))?(!)?: ([\\w ])+([\\s\\S]*)",
"on_property": "title",
"target": "$1"
}
]
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub release
if: ${{ env.SKIP != 'true' }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.version }}
name: Release ${{ env.version }}
body: "Automated release for version ${{ env.version }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push dev VERSION
if: ${{ env.SKIP != 'true' }}
run: |
echo "${{ env.version }}-dev" > VERSION
git config user.name "${{ env.AUTHOR_NAME }}"
git config user.email "${{ env.AUTHOR_EMAIL }}"
git add VERSION
git commit -m "Update VERSION to ${{ env.version }}-dev"
git push origin main
5 changes: 3 additions & 2 deletions .github/workflows/reuse-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ name: REUSE Compliance Check

on:
workflow_call: {}
pull_request:
push:
branches:
- main

pull_request:


jobs:
lint-reuse:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/reviewable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ name: make reviewable && make check-Diff

on:
workflow_call: {}
pull_request:
push:
tags:
- v*
branches:
- main
pull_request:
env:
GO_IMPORT_VERSION: 'v0.16.1'

Expand Down Expand Up @@ -35,7 +38,10 @@ jobs:

- name: tidy
run: go mod tidy


- name: sync chart version
run: make helm-chart

- name: make check-diff
run: make check-diff

Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ docker-push: ## Push docker image with the manager.
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
# To properly provided solutions that supports more than one platform you should use this option.
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
PLATFORMS ?= linux/arm64 linux/amd64
.PHONY: docker-buildx
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
docker-buildx: #test ## Build and tag docker image for each platform locally using --load
sed '1 s/^FROM/FROM --platform=$${BUILDPLATFORM}/' Dockerfile > Dockerfile.cross
$(CONTAINER_TOOL) buildx create --name project-v3-builder || true
$(CONTAINER_TOOL) buildx use project-v3-builder
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
- $(CONTAINER_TOOL) buildx rm project-v3-builder
@for platform in $(PLATFORMS); do \
tag="$(IMG)-$$(echo $$platform | tr / -)"; \
echo "Building $$tag for $$platform"; \
$(CONTAINER_TOOL) buildx build --platform=$$platform --tag $$tag --load -f Dockerfile.cross .; \
done
$(CONTAINER_TOOL) buildx rm project-v3-builder
rm Dockerfile.cross

##@ Deployment
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.5.0
1 change: 1 addition & 0 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type GroupVersionKind struct {
Version string `json:"version,omitempty"`
}

// GVK returns the schema.GroupVersionKind object of v1alpha1 GVK
func (gvk *GroupVersionKind) GVK() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: gvk.Group,
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/metric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (r *Metric) SetConditions(conditions ...metav1.Condition) {
meta.SetStatusCondition(&r.Status.Conditions, c)
}
}

// GvkToString returns the string representation of the metric targe GVK
func (r *Metric) GvkToString() string {
if r.Spec.Target.Group == "" {
return fmt.Sprintf("/%s, Kind=%s", r.Spec.Target.Version, r.Spec.Target.Kind)
Expand Down
6 changes: 3 additions & 3 deletions charts/metrics-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: metrics-operator
description: A Helm chart for the co-metrics-operator
description: A Helm chart for the metrics-operator
type: application
version: 0.4.2
appVersion: 0.4.2
version: v0.5.0
appVersion: v0.5.0
4 changes: 2 additions & 2 deletions charts/metrics-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
replicaCount: 1

image:
repository: ghcr.io/SAP/metrics-operator
repository: deploy-releases-hyperspace-docker.common.cdn.repositories.cloud.sap/cloud-orchestration/co-metrics-operator
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: 0.4.2
tag: v0.5.0

imagePullSecrets: []
nameOverride: ""
Expand Down
21 changes: 21 additions & 0 deletions component-constructor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
components:
- name: ${COMPONENT_NAME_PREFIX}/${COMPONENT_NAME}
version: ${VERSION}
provider:
name: ${PROVIDER}
resources:
- name: ${COMPONENT_NAME}-chart
type: helmChart
input:
type: helm
path: ./charts/${COMPONENT_NAME}
repository: charts/${COMPONENT_NAME}

- name: ${COMPONENT_NAME}-image
type: ociImage
input:
type: dockermulti
repository: images/${COMPONENT_NAME}
variants:
- "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-amd64"
- "${COMPONENT_REPO_PREFIX}:${VERSION}-linux-arm64"
1 change: 1 addition & 0 deletions internal/orchestrator/metrichandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func NewMetricHandler(metric v1alpha1.Metric, qc QueryConfig, gaugeMetric *clien
return handler, nil
}

// GetGVRfromGVK converts GVK to GVR
func GetGVRfromGVK(gvk schema.GroupVersionKind, disco discovery.DiscoveryInterface) (schema.GroupVersionResource, error) {
// TODO: this could be optimized later (e.g. by caching the discovery client)
groupResources, err := disco.ServerResourcesForGroupVersion(gvk.GroupVersion().String())
Expand Down
4 changes: 4 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
COMPONENT_NAME: metrics-operator
COMPONENT_NAME_PREFIX: github.com/sap
PROVIDER: openmcp-project
COMPONENT_REPO_PREFIX: ghcr.io/sap/metrics-operator