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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY cmd/manager/main.go cmd/manager/main.go
COPY api/ api/
COPY internal/ internal/

Expand All @@ -24,7 +24,7 @@ COPY internal/ internal/
# Build
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ lint-config: golangci-lint ## Verify golangci-lint linter configuration

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
go build -o bin/manager cmd/manager/main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
go run ./cmd/manager/main.go

# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ With this operator it is possible to:
To find out more, please refer to:
- [installation and deployment](/docs/installation.md)
- [usage](/docs/usage.md)
- [ipamctl](/docs/ipamctl.md)
- [consuming api](docs/consuming_api.md)
- [development](/docs/development.md)
- [contribution guide](/docs/contribution.md)
Expand Down
10 changes: 5 additions & 5 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ path = [
"README.md",
"api/**",
"charts/**",
"cmd/**",
"cmdutils/**",
"config/**",
"controllers/**",
"clientset/**",
"clientgo/**",
"go.mod",
"go.sum",
"hack/**","main.go",
"internal/**",
"REUSE.toml"
]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 SAP SE or an SAP affiliate company and IronCore contributors"
SPDX-FileCopyrightText = "2025 SAP SE or an SAP affiliate company and IronCore contributors"
SPDX-License-Identifier = "Apache-2.0"

[[annotations]]
path = ["docs/**", "README.md"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 SAP SE or an SAP affiliate company and IronCore contributors"
SPDX-FileCopyrightText = "2025 SAP SE or an SAP affiliate company and IronCore contributors"
SPDX-License-Identifier = "Apache-2.0"
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/cidr_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/cidr_types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/cidrutils.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// +k8s:deepcopy-gen=package
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

// Package v1alpha1 contains API Schema definitions for the ipam v1alpha1 API group
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/ip_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/ipaddr_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/ipaddr_types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/network_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/network_types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/networkcounter_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/networkcounter_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/networkid_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/networkid_types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/networkidinterval_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/resourcereference_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/subnet_types_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1
Expand Down
2 changes: 1 addition & 1 deletion api/ipam/v1alpha1/zz_generated.deepcopy.go

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

34 changes: 34 additions & 0 deletions cmd/ipamctl/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package app

import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"

ipamv1alphav1 "github.com/ironcore-dev/ipam/api/ipam/v1alpha1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
)

const Name string = "ipamctl"

var scheme = runtime.NewScheme()

func init() {
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(ipamv1alphav1.AddToScheme(scheme))
}

func NewCommand() *cobra.Command {
root := &cobra.Command{
Use: Name,
Short: "CLI client for ipam",
Args: cobra.NoArgs,
}
root.AddCommand(NewMoveCommand())
return root
}
98 changes: 98 additions & 0 deletions cmd/ipamctl/app/move.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package app

import (
"fmt"
"log/slog"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/controller-runtime/pkg/client"

ipamv1alpha1 "github.com/ironcore-dev/ipam/api/ipam/v1alpha1"
utils "github.com/ironcore-dev/ipam/cmdutils"
)

var (
sourceKubeconfig string
targetKubeconfig string
namespace string
requireOwners bool
dryRun bool
verbose bool
)

func NewMoveCommand() *cobra.Command {
move := &cobra.Command{
Use: "move",
Short: "Move IPAM CRs from one cluster to another",
RunE: runMove,
}
move.Flags().StringVar(&sourceKubeconfig, "source-kubeconfig", "", "Kubeconfig pointing to the source cluster")
move.Flags().StringVar(&targetKubeconfig, "target-kubeconfig", "", "Kubeconfig pointing to the target cluster")
move.Flags().StringVar(&namespace, "namespace", "",
"namespace to filter CRs to migrate. Defaults to all namespaces if not specified")
move.Flags().BoolVar(&requireOwners, "require-owners", false,
"if set to true, an error will be returned if for any custom resource an owner ServerBootConfiguration") //nolint:lll
move.Flags().BoolVar(&dryRun, "dry-run", false, "show what would be moved without executing the migration")
move.Flags().BoolVar(&verbose, "verbose", false, "enable verbose logging for detailed output during migration")
_ = move.MarkFlagRequired("source-kubeconfig")
_ = move.MarkFlagRequired("target-kubeconfig")

if verbose {
slog.SetLogLoggerLevel(slog.LevelDebug)
}
return move
}

func makeClient(kubeconfig string) (client.Client, error) {
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, fmt.Errorf("failed to load cluster kubeconfig: %w", err)
}
return client.New(cfg, client.Options{Scheme: scheme})
}

func makeClients() (utils.Clients, error) {
var clients utils.Clients
var err error

clients.Source, err = makeClient(sourceKubeconfig)
if err != nil {
return clients, fmt.Errorf("failed to construct a source cluster client: %w", err)
}
clients.Target, err = makeClient(targetKubeconfig)
if err != nil {
return clients, fmt.Errorf("failed to construct a target cluster client: %w", err)
}
return clients, nil
}

func runMove(cmd *cobra.Command, args []string) error {
clients, err := makeClients()
if err != nil {
return err
}
ctx := cmd.Context()

crdList := &apiextensionsv1.CustomResourceDefinitionList{}
if err := clients.Source.List(ctx, crdList); err != nil {
return err
}
crsSchema := []schema.GroupVersionKind{}
for _, crd := range crdList.Items {
if crd.Spec.Group == ipamv1alpha1.SchemeGroupVersion.Group {
crsSchema = append(crsSchema, schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[0].Name,
Kind: crd.Spec.Names.Kind,
})
}
}
return utils.Move(ctx, clients, crsSchema, namespace, dryRun)
}
19 changes: 19 additions & 0 deletions cmd/ipamctl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package main

import (
"fmt"
"os"

"github.com/ironcore-dev/ipam/cmd/ipamctl/app"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

func main() {
if err := app.NewCommand().ExecuteContext(signals.SetupSignalHandler()); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion cmd/main.go → cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package main
Expand Down
11 changes: 11 additions & 0 deletions cmdutils/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package cmdutils

import "sigs.k8s.io/controller-runtime/pkg/client"

type Clients struct {
Source client.Client
Target client.Client
}
Loading
Loading