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
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Image URL to use all building/pushing image targets
REGISTRY ?= ghcr.io
IMAGE_ORG ?= stackitcloud
IS_DEV ?= true
VERSION := $(shell git describe --tag --always --dirty)
REGISTRY ?= ghcr.io
IMAGE_ORG ?= stackitcloud
IMAGE_TAGS := $(VERSION),latest
IS_DEV ?= true
ifeq ($(IS_DEV),true)
REPO_POSTFIX := -dev
REPO_POSTFIX := -dev
IMAGE_TAGS := $(VERSION)
endif
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
HACK_DIR := $(REPO_ROOT)/hack
VERSION := $(shell git describe --tag --always --dirty)
REPO_ROOT := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
HACK_DIR := $(REPO_ROOT)/hack

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit immediately on error, unset variables, and pipe failures.
Expand Down Expand Up @@ -84,7 +86,7 @@ image-%: ## Builds a specific image using ko (e.g., make image-stackit-workload-
KO_DOCKER_REPO=$(REGISTRY)/$(IMAGE_ORG)/$*$(REPO_POSTFIX) \
go tool ko build --push=$(PUSH) \
--image-label org.opencontainers.image.source="https://github.com/stackitcloud/stackit-pod-identity-webhook" \
--sbom none -t $(VERSION) \
--sbom none -t $(IMAGE_TAGS) \
--bare \
--platform linux/amd64,linux/arm64 \
./cmd/$* \
Expand All @@ -100,4 +102,4 @@ artifacts: images chart ## Pushes all artifacts including image and helm chart
.PHONY: clean
clean: ## Clean binaries and image files
rm -rf bin/
rm -f image-*.txt
rm -f image-*.txt
41 changes: 21 additions & 20 deletions cmd/stackit-workload-identity-example-app/main.go
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
// Package main provides a simple example application that demonstrates the use of STACKIT Workload Identity.
// It uses the STACKIT Go SDK to interact with the SKE API, relying on the identity injected
// by the stackit-pod-identity-webhook for authentication.
// Getting the provider options does not require any permissions to be assigned to the ServiceAccount.
// Getting the public IP ranges does not require any permissions to be assigned to the ServiceAccount.
package main

import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"

"github.com/stackitcloud/stackit-sdk-go/core/config"
ske "github.com/stackitcloud/stackit-sdk-go/services/ske/v2api"
iaas "github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api"
)

const defaultRegion = "eu01"

func main() {
if err := run(); err != nil {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

if err := run(ctx); err != nil {
slog.Error("Application failed", "error", err)
os.Exit(1)
}
}

func run() error {
region := os.Getenv("STACKIT_REGION")
if region == "" {
region = defaultRegion
}

func run(ctx context.Context) error {
var opts []config.ConfigurationOption
if endpoint := os.Getenv("STACKIT_SKE_ENDPOINT"); endpoint != "" {
slog.Info("Using custom SKE endpoint", "endpoint", endpoint)
if endpoint := os.Getenv("STACKIT_IAAS_API_ENDPOINT"); endpoint != "" {
slog.Info("Using custom IaaS API endpoint", "endpoint", endpoint)
opts = append(opts, config.WithEndpoint(endpoint))
}

// Create a new API client that uses default authentication and configuration
skeClient, err := ske.NewAPIClient(opts...)
iaasClient, err := iaas.NewAPIClient(opts...)
if err != nil {
return fmt.Errorf("creating API client: %w", err)
}

slog.Info("Fetching SKE options", "region", region)
getOptionsResp, err := skeClient.DefaultAPI.ListProviderOptions(context.Background(), region).Execute()
slog.Info("Fetching public IP ranges")

publicIpRangesResponse, err := iaasClient.DefaultAPI.ListPublicIPRanges(ctx).Execute()

if err != nil {
return fmt.Errorf("calling ListProviderOptions: %w", err)
return fmt.Errorf("calling ListPublicIPRanges: %w", err)
}

slog.Info("Authentication successful, API call succeeded")

availableVersions := getOptionsResp.KubernetesVersions
if len(availableVersions) == 0 {
slog.Warn("No Kubernetes versions found", "region", region)
publicIpRanges := publicIpRangesResponse.Items

if len(publicIpRanges) == 0 {
slog.Warn("No public IP ranges found. There might be a problem with the autentication.")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.1
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
github.com/stackitcloud/stackit-sdk-go/services/ske v1.12.0
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.11.1
k8s.io/api v0.35.1
k8s.io/apimachinery v0.35.1
k8s.io/client-go v0.35.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YE
github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I=
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA=
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.12.0 h1:G6iUFDlrwCkCkwSV3eLNsFpVD24h6qV7D4pm0rqftnM=
github.com/stackitcloud/stackit-sdk-go/services/ske v1.12.0/go.mod h1:cSRF2ARIB6dKmvZ12Z5h1usKQligeZJ1JOiJk6Ds3wE=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.11.1 h1:HcKqjwIjv4OAW1aWI0U/JWjnzTwzSvdr6DLasH940EU=
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.11.1/go.mod h1:Ts06id0KejUlQWbpR+/rm+tKng6QkTuFV1VQTPJ4dA4=
github.com/stbenjam/no-sprintf-host-port v0.2.0 h1:i8pxvGrt1+4G0czLr/WnmyH7zbZ8Bg8etvARQ1rpyl4=
github.com/stbenjam/no-sprintf-host-port v0.2.0/go.mod h1:eL0bQ9PasS0hsyTyfTjjG+E80QIyPnBVQbYZyv20Jfk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down