Skip to content
Open
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
13 changes: 13 additions & 0 deletions .github/actions/prepare-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Prepare-Release

runs:
using: composite
steps:
- uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: prepare-release
shell: bash
run: |
set -eu
make generate
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
uses: gardener/cc-utils/.github/workflows/prepare.yaml@v1
with:
mode: ${{ inputs.mode }}
version-operation: ${{ inputs.release-version }}
version-commit-callback-action-path: .github/actions/prepare-release
permissions:
id-token: write

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
with:
release-commit-target: branch
next-version: ${{ inputs.next-version }}
next-version-callback-action-path: .github/actions/prepare-release
assets: |
- name: gardener-landscape-kit-darwin-amd64
type: ocm-resource
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ generate: tools-for-generate $(GOIMPORTS) $(FLUX_CLI) $(YQ)
@REPO_ROOT=$(REPO_ROOT) GARDENER_HACK_DIR=$(GARDENER_HACK_DIR) $(HACK_DIR)/update-codegen.sh
@GARDENER_HACK_DIR=$(GARDENER_HACK_DIR) $(HACK_DIR)/update-github-templates.sh
@GARDENER_HACK_DIR=$(GARDENER_HACK_DIR) $(HACK_DIR)/generate-renovate-ignore-deps.sh
@$(HACK_DIR)/sync-glk-version.sh
$(MAKE) format

.PHONY: check
Expand Down
2 changes: 2 additions & 0 deletions componentvector/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions componentvector/components.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
components:
- name: github.com/gardener/gardener-landscape-kit
sourceRepository: https://github.com/gardener/gardener-landscape-kit
version: v0.2.0-dev
- name: github.com/gardener/gardener
sourceRepository: https://github.com/gardener/gardener
version: v1.140.0
Expand Down Expand Up @@ -122,11 +125,11 @@ components:
helmChart:
repository: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/extensions/shoot-dns-service-admission-runtime
shootDnsServiceAdmissionApplication:
helmChart:
repository: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/extensions/shoot-dns-service-admission-application
helmChart:
repository: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/extensions/shoot-dns-service-admission-application
shootDnsService:
helmChart:
repository: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/extensions/shoot-dns-service
helmChart:
repository: europe-docker.pkg.dev/gardener-project/releases/charts/gardener/extensions/shoot-dns-service
- name: github.com/gardener/gardener-extension-shoot-oidc-service
sourceRepository: https://github.com/gardener/gardener-extension-shoot-oidc-service
version: v0.38.0
Expand Down
18 changes: 18 additions & 0 deletions docs/api-reference/landscapekit-v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ _Appears in:_
| `landscape` _string_ | Landscape is the relative path to the landscape directory within the Git repository. | | Required: \{\} <br /> |


#### VersionCheckMode

_Underlying type:_ _string_

VersionCheckMode controls the behavior when the tool version doesn't match the component version.



_Appears in:_
- [VersionConfiguration](#versionconfiguration)

| Field | Description |
| --- | --- |
| `Strict` | VersionCheckModeStrict indicates that version mismatches should cause an error.<br /> |
| `Warning` | VersionCheckModeWarning indicates that version mismatches should only log a warning.<br /> |


#### VersionConfiguration


Expand All @@ -147,5 +164,6 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `defaultVersionsUpdateStrategy` _[DefaultVersionsUpdateStrategy](#defaultversionsupdatestrategy)_ | UpdateStrategy determines whether the versions in the default vector should be updated from the release branch on resolve.<br />Possible values are "Disabled" (default) and "ReleaseBranch". | | Optional: \{\} <br /> |
| `checkMode` _[VersionCheckMode](#versioncheckmode)_ | CheckMode determines the behavior when the tool version doesn't match the gardener-landscape-kit version in the component vector.<br />Possible values are "Strict" (default) and "Warning".<br />In strict mode, version mismatches cause errors. In warning mode, only warnings are logged. | | Optional: \{\} <br /> |


1 change: 1 addition & 0 deletions example/20-componentconfig-glk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ kind: LandscapeKitConfiguration
# - component-name
# versionConfig:
# defaultVersionsUpdateStrategy: ReleaseBranch
# checkMode: Strict # or Warning
51 changes: 51 additions & 0 deletions hack/sync-glk-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

set -o errexit
set -o nounset
set -o pipefail

# This script syncs the gardener-landscape-kit component version in
# componentvector/components.yaml with the version specified in the VERSION file.
# If the component doesn't exist, it adds it as the first entry.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
VERSION_FILE="$REPO_ROOT/VERSION"
COMPONENTS_FILE="$REPO_ROOT/componentvector/components.yaml"

# Read the VERSION file
if [[ ! -f "$VERSION_FILE" ]]; then
echo "ERROR: VERSION file not found at $VERSION_FILE" >&2
exit 1
fi

VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]')

if [[ -z "$VERSION" ]]; then
echo "ERROR: VERSION file is empty" >&2
exit 1
fi

# Check if components.yaml exists
if [[ ! -f "$COMPONENTS_FILE" ]]; then
echo "ERROR: components.yaml not found at $COMPONENTS_FILE" >&2
exit 1
fi

GLK_COMPONENT_NAME="github.com/gardener/gardener-landscape-kit"
REPO_URL="https://$GLK_COMPONENT_NAME"

# Check if the GLK component already exists in the file
if [[ $(yq eval '[.components[] | select(.name == "'"$GLK_COMPONENT_NAME"'")] | length' "$COMPONENTS_FILE") -gt 0 ]]; then
# Component exists - update its version
yq eval -i --indent 2 -c "(.components[] | select(.name == \"$GLK_COMPONENT_NAME\") | .version) = \"$VERSION\"" "$COMPONENTS_FILE"
echo "Updated $GLK_COMPONENT_NAME component version to $VERSION"
else
# Component doesn't exist - prepend it as the first entry
yq eval -i --indent 2 -c ".components = [{\"name\": \"$GLK_COMPONENT_NAME\", \"sourceRepository\": \"$REPO_URL\", \"version\": \"$VERSION\"}] + .components" "$COMPONENTS_FILE"
echo "Added $GLK_COMPONENT_NAME component with version $VERSION as first entry"
fi
21 changes: 21 additions & 0 deletions pkg/apis/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,31 @@ var AllowedDefaultVersionsUpdateStrategies = []string{
string(DefaultVersionsUpdateStrategyDisabled),
}

// VersionCheckMode controls the behavior when the tool version doesn't match the component version.
type VersionCheckMode string

const (
// VersionCheckModeStrict indicates that version mismatches should cause an error.
VersionCheckModeStrict VersionCheckMode = "Strict"
// VersionCheckModeWarning indicates that version mismatches should only log a warning.
VersionCheckModeWarning VersionCheckMode = "Warning"
)

// AllowedVersionCheckModes lists all allowed version check modes.
var AllowedVersionCheckModes = []string{
string(VersionCheckModeStrict),
string(VersionCheckModeWarning),
}

// VersionConfiguration contains configuration for versioning.
type VersionConfiguration struct {
// UpdateStrategy determines whether the versions in the default vector should be updated from the release branch on resolve.
// Possible values are "Disabled" (default) and "ReleaseBranch".
// +optional
DefaultVersionsUpdateStrategy *DefaultVersionsUpdateStrategy `json:"defaultVersionsUpdateStrategy,omitempty"`
// CheckMode determines the behavior when the tool version doesn't match the gardener-landscape-kit version in the component vector.
// Possible values are "Strict" (default) and "Warning".
// In strict mode, version mismatches cause errors. In warning mode, only warnings are logged.
// +optional
CheckMode *VersionCheckMode `json:"checkMode,omitempty"`
}
4 changes: 4 additions & 0 deletions pkg/apis/config/v1alpha1/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,9 @@ func ValidateVersionConfig(conf *configv1alpha1.VersionConfiguration, fldPath *f
allErrs = append(allErrs, field.Invalid(fldPath.Child("defaultVersionsUpdateStrategy"), *conf.DefaultVersionsUpdateStrategy, "allowed values are: "+strings.Join(configv1alpha1.AllowedDefaultVersionsUpdateStrategies, ", ")))
}

if conf.CheckMode != nil && !slices.Contains(configv1alpha1.AllowedVersionCheckModes, string(*conf.CheckMode)) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("checkMode"), *conf.CheckMode, "allowed values are: "+strings.Join(configv1alpha1.AllowedVersionCheckModes, ", ")))
}

return allErrs
}
5 changes: 5 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/cmd/generate/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func run(_ context.Context, opts *options.Options) error {
return fmt.Errorf("failed to register components: %w", err)
}

if err := version.CheckGLKComponentVersion(componentOpts.GetComponentVector(), opts.Config, opts.Log); err != nil {
return fmt.Errorf("version check failed: %w", err)
}

if err := reg.GenerateBase(componentOpts); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/generate/landscape/landscape.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func run(_ context.Context, opts *options.Options) error {
return fmt.Errorf("failed to create component options: %w", err)
}

if err := version.CheckGLKComponentVersion(componentOpts.GetComponentVector(), opts.Config, opts.Log); err != nil {
return fmt.Errorf("version validation failed: %w", err)
}

reg := registry.New()
if err := registry.RegisterAllComponents(reg, opts.Config); err != nil {
return fmt.Errorf("failed to register components: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions pkg/components/gardener/landscape-kit/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0

package landscapekit

const (
// ComponentName is the name of the gardener-landscape-kit component.
ComponentName = "gardener-landscape-kit"
)
37 changes: 37 additions & 0 deletions pkg/utils/version/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (
"strings"

"github.com/Masterminds/semver/v3"
"github.com/go-logr/logr"
"github.com/spf13/afero"
apimachineryversion "k8s.io/apimachinery/pkg/version"
componentbaseversion "k8s.io/component-base/version"

"github.com/gardener/gardener-landscape-kit/componentvector"
configv1alpha1 "github.com/gardener/gardener-landscape-kit/pkg/apis/config/v1alpha1"
utilscomponentvector "github.com/gardener/gardener-landscape-kit/pkg/utils/componentvector"
"github.com/gardener/gardener-landscape-kit/pkg/utils/files"
)

Expand Down Expand Up @@ -139,6 +143,39 @@ func ValidateLandscapeVersionCompatibility(targetPath string, fs afero.Afero) er
return ValidateVersionCompatibility(baseMetadata.Version, version.GitVersion)
}

// CheckGLKComponentVersion validates that the tool version matches the gardener-landscape-kit
// component version in the component vector.
// The behavior depends on the checkMode in the configuration:
// - If checkMode is "Strict" (or nil/default), returns an error on mismatch.
// - If checkMode is "Warning", logs a warning on mismatch and returns nil.
func CheckGLKComponentVersion(cv utilscomponentvector.Interface, config *configv1alpha1.LandscapeKitConfiguration, log logr.Logger) error {
toolVersion := version.GitVersion
componentVersion, found := cv.FindComponentVersion(componentvector.NameGardenerGardenerLandscapeKit)

if !found {
return fmt.Errorf("gardener-landscape-kit component not found in component vector - this should not happen as it's part of the default component vector")
}

if toolVersion != componentVersion {
// Determine the check mode (default to Strict)
checkMode := configv1alpha1.VersionCheckModeStrict
if config != nil && config.VersionConfig != nil && config.VersionConfig.CheckMode != nil {
checkMode = *config.VersionConfig.CheckMode
}

err := fmt.Errorf("version mismatch: tool version (%s) does not match gardener-landscape-kit component version (%s) in component vector - obtain the matching gardener-landscape-kit version or adjust the component vector", toolVersion, componentVersion)

if checkMode == configv1alpha1.VersionCheckModeWarning {
log.Error(err, "Precheck failed")
return nil
}

return err
}

return nil
}

// Get returns the version of GLK.
func Get() apimachineryversion.Info {
return version
Expand Down
Loading
Loading