Skip to content

Commit 7899415

Browse files
committed
change mcp controller to platform service
1 parent a690e89 commit 7899415

File tree

22 files changed

+801
-205
lines changed

22 files changed

+801
-205
lines changed

api/crds/manifests/openmcp.cloud_clusterproviders.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,14 +1933,20 @@ spec:
19331933
ImagePullSecrets are secrets in the same namespace.
19341934
They can be used to fetch provider images from private registries.
19351935
items:
1936+
description: LocalObjectReference is a reference to an object in
1937+
the same namespace as the resource referencing it.
19361938
properties:
19371939
name:
1938-
description: Name is the name of the referenced resource.
1939-
minLength: 1
1940+
default: ""
1941+
description: |-
1942+
Name of the referent.
1943+
This field is effectively required, but due to backwards compatibility is
1944+
allowed to be empty. Instances of this type with an empty value here are
1945+
almost certainly wrong.
1946+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
19401947
type: string
1941-
required:
1942-
- name
19431948
type: object
1949+
x-kubernetes-map-type: atomic
19441950
type: array
19451951
initCommand:
19461952
description: |-

api/crds/manifests/openmcp.cloud_platformservices.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,14 +1933,20 @@ spec:
19331933
ImagePullSecrets are secrets in the same namespace.
19341934
They can be used to fetch provider images from private registries.
19351935
items:
1936+
description: LocalObjectReference is a reference to an object in
1937+
the same namespace as the resource referencing it.
19361938
properties:
19371939
name:
1938-
description: Name is the name of the referenced resource.
1939-
minLength: 1
1940+
default: ""
1941+
description: |-
1942+
Name of the referent.
1943+
This field is effectively required, but due to backwards compatibility is
1944+
allowed to be empty. Instances of this type with an empty value here are
1945+
almost certainly wrong.
1946+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
19401947
type: string
1941-
required:
1942-
- name
19431948
type: object
1949+
x-kubernetes-map-type: atomic
19441950
type: array
19451951
initCommand:
19461952
description: |-

api/crds/manifests/openmcp.cloud_serviceproviders.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,14 +1933,20 @@ spec:
19331933
ImagePullSecrets are secrets in the same namespace.
19341934
They can be used to fetch provider images from private registries.
19351935
items:
1936+
description: LocalObjectReference is a reference to an object in
1937+
the same namespace as the resource referencing it.
19361938
properties:
19371939
name:
1938-
description: Name is the name of the referenced resource.
1939-
minLength: 1
1940+
default: ""
1941+
description: |-
1942+
Name of the referent.
1943+
This field is effectively required, but due to backwards compatibility is
1944+
allowed to be empty. Instances of this type with an empty value here are
1945+
almost certainly wrong.
1946+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
19401947
type: string
1941-
required:
1942-
- name
19431948
type: object
1949+
x-kubernetes-map-type: atomic
19441950
type: array
19451951
initCommand:
19461952
description: |-

api/install/install.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@ func InstallCRDAPIs(scheme *runtime.Scheme) *runtime.Scheme {
2020
return scheme
2121
}
2222

23-
func InstallOperatorAPIs(scheme *runtime.Scheme) *runtime.Scheme {
23+
func InstallOperatorAPIsPlatform(scheme *runtime.Scheme) *runtime.Scheme {
2424
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
2525
utilruntime.Must(providerv1alpha1.AddToScheme(scheme))
2626
utilruntime.Must(clustersv1alpha1.AddToScheme(scheme))
27+
28+
return scheme
29+
}
30+
31+
func InstallOperatorAPIsOnboarding(scheme *runtime.Scheme) *runtime.Scheme {
32+
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
2733
utilruntime.Must(corev2alpha1.AddToScheme(scheme))
2834

2935
return scheme

api/provider/v1alpha1/deployment_types.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package v1alpha1
1919
import (
2020
corev1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
23+
"github.com/openmcp-project/openmcp-operator/api/common"
2224
)
2325

2426
// DeploymentSpec defines the desired state of a provider.
@@ -29,7 +31,7 @@ type DeploymentSpec struct {
2931

3032
// ImagePullSecrets are secrets in the same namespace.
3133
// They can be used to fetch provider images from private registries.
32-
ImagePullSecrets []ObjectReference `json:"imagePullSecrets,omitempty"`
34+
ImagePullSecrets []common.LocalObjectReference `json:"imagePullSecrets,omitempty"`
3335

3436
// InitCommand is the command that is executed to run the init job of the provider.
3537
// Defaults to ["init"], if not specified.
@@ -86,12 +88,6 @@ type DeploymentStatus struct {
8688
Phase string `json:"phase,omitempty"`
8789
}
8890

89-
type ObjectReference struct {
90-
// Name is the name of the referenced resource.
91-
// +kubebuilder:validation:MinLength=1
92-
Name string `json:"name"`
93-
}
94-
9591
// EnvVar represents an environment variable present in a Container.
9692
type EnvVar struct {
9793
// Name is the name of the environment variable.

api/provider/v1alpha1/zz_generated.deepcopy.go

Lines changed: 3 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/openmcp-operator/app/app.go

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ package app
22

33
import (
44
"context"
5-
"fmt"
65
"os"
76

8-
ctrl "sigs.k8s.io/controller-runtime"
9-
"sigs.k8s.io/yaml"
10-
117
"github.com/spf13/cobra"
128

13-
"github.com/openmcp-project/controller-utils/pkg/clusters"
14-
"github.com/openmcp-project/controller-utils/pkg/logging"
15-
16-
"github.com/openmcp-project/openmcp-operator/internal/config"
9+
"github.com/openmcp-project/openmcp-operator/cmd/openmcp-operator/app/mcp"
10+
"github.com/openmcp-project/openmcp-operator/cmd/openmcp-operator/app/options"
1711
)
1812

1913
func NewOpenMCPOperatorCommand(ctx context.Context) *cobra.Command {
@@ -24,110 +18,11 @@ func NewOpenMCPOperatorCommand(ctx context.Context) *cobra.Command {
2418
cmd.SetOut(os.Stdout)
2519
cmd.SetErr(os.Stderr)
2620

27-
so := &SharedOptions{
28-
RawSharedOptions: &RawSharedOptions{},
29-
PlatformCluster: clusters.New("platform"),
30-
}
31-
so.AddPersistentFlags(cmd)
32-
cmd.AddCommand(NewInitCommand(so))
33-
cmd.AddCommand(NewRunCommand(so))
21+
po := options.NewPersistentOptions()
22+
po.AddPersistentFlags(cmd)
23+
cmd.AddCommand(NewInitCommand(po))
24+
cmd.AddCommand(NewRunCommand(po))
25+
cmd.AddCommand(mcp.NewMCPControllerSubcommand(ctx, po))
3426

3527
return cmd
3628
}
37-
38-
type RawSharedOptions struct {
39-
Environment string `json:"environment"`
40-
DryRun bool `json:"dry-run"`
41-
ConfigPaths []string `json:"configPaths"`
42-
PlatformClusterKubeconfigPath string `json:"kubeconfig"` // dummy for printing, actual path is in Clusters
43-
}
44-
45-
type SharedOptions struct {
46-
*RawSharedOptions
47-
PlatformCluster *clusters.Cluster
48-
49-
// fields filled in Complete()
50-
Log logging.Logger
51-
Config *config.Config
52-
}
53-
54-
func (o *SharedOptions) AddPersistentFlags(cmd *cobra.Command) {
55-
// logging
56-
logging.InitFlags(cmd.PersistentFlags())
57-
// clusters
58-
o.PlatformCluster.RegisterSingleConfigPathFlag(cmd.PersistentFlags())
59-
// environment
60-
cmd.PersistentFlags().StringVar(&o.Environment, "environment", "", "Environment name. Required. This is used to distinguish between different environments that are watching the same Onboarding cluster. Must be globally unique.")
61-
// config
62-
cmd.PersistentFlags().StringSliceVar(&o.ConfigPaths, "config", nil, "Paths to the config files (separate with comma or specify flag multiple times). Each path can be a file or directory. In the latter case, all files within with '.yaml', '.yml', and '.json' extensions are evaluated. The config is merged together from the different sources, with later configs overriding earlier ones.")
63-
// misc
64-
cmd.PersistentFlags().BoolVar(&o.DryRun, "dry-run", false, "If set, the command aborts after evaluation of the given flags.")
65-
}
66-
67-
func (o *SharedOptions) Complete() error {
68-
if o.Environment == "" {
69-
return fmt.Errorf("environment must not be empty")
70-
}
71-
config.SetEnvironment(o.Environment)
72-
73-
// build logger
74-
log, err := logging.GetLogger()
75-
if err != nil {
76-
return err
77-
}
78-
o.Log = log
79-
ctrl.SetLogger(o.Log.Logr())
80-
81-
// construct cluster clients
82-
if err := o.PlatformCluster.InitializeRESTConfig(); err != nil {
83-
return err
84-
}
85-
86-
// load config
87-
if len(o.ConfigPaths) > 0 {
88-
cfg, err := config.LoadFromFiles(o.ConfigPaths...)
89-
if err != nil {
90-
return fmt.Errorf("error loading config from files: %w", err)
91-
}
92-
if err := cfg.Default(); err != nil {
93-
_ = cfg.Dump(os.Stderr)
94-
return fmt.Errorf("error defaulting config: %w", err)
95-
}
96-
if err := cfg.Validate(); err != nil {
97-
_ = cfg.Dump(os.Stderr)
98-
return fmt.Errorf("config is invalid: %w", err)
99-
}
100-
if err := cfg.Complete(); err != nil {
101-
_ = cfg.Dump(os.Stderr)
102-
return fmt.Errorf("error completing config: %w", err)
103-
}
104-
o.Config = cfg
105-
}
106-
107-
return nil
108-
}
109-
110-
func (o *SharedOptions) PrintRaw(cmd *cobra.Command) {
111-
// fill dummy paths
112-
o.PlatformClusterKubeconfigPath = o.PlatformCluster.ConfigPath()
113-
114-
data, err := yaml.Marshal(o.RawSharedOptions)
115-
if err != nil {
116-
cmd.Println(fmt.Errorf("error marshalling raw shared options: %w", err).Error())
117-
return
118-
}
119-
cmd.Print(string(data))
120-
}
121-
122-
func (o *SharedOptions) PrintCompleted(cmd *cobra.Command) {
123-
raw := map[string]any{
124-
"platformCluster": o.PlatformCluster.APIServerEndpoint(),
125-
"config": o.Config,
126-
}
127-
data, err := yaml.Marshal(raw)
128-
if err != nil {
129-
cmd.Println(fmt.Errorf("error marshalling completed shared options: %w", err).Error())
130-
return
131-
}
132-
cmd.Print(string(data))
133-
}

0 commit comments

Comments
 (0)