Skip to content

Commit 8c78233

Browse files
authored
Deployment Controller (#14)
1 parent b138429 commit 8c78233

File tree

16 files changed

+190
-68
lines changed

16 files changed

+190
-68
lines changed

api/crds/manifests/openmcp.cloud_clusterproviders.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
- image
6464
type: object
6565
status:
66-
description: DeploymentStatus defines the observed state of a provider.
66+
description: ClusterProviderStatus defines the observed state of ClusterProvider.
6767
properties:
6868
conditions:
6969
items:

api/crds/manifests/openmcp.cloud_platformservices.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
- image
6464
type: object
6565
status:
66-
description: DeploymentStatus defines the observed state of a provider.
66+
description: PlatformServiceStatus defines the observed state of PlatformService.
6767
properties:
6868
conditions:
6969
items:

api/crds/manifests/openmcp.cloud_serviceproviders.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
- image
6464
type: object
6565
status:
66-
description: DeploymentStatus defines the observed state of a provider.
66+
description: ServiceProviderStatus defines the observed state of ServiceProvider.
6767
properties:
6868
conditions:
6969
items:

api/provider/v1alpha1/clusterprovider_types.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type ClusterProviderSpec struct {
3131

3232
// ClusterProviderStatus defines the observed state of ClusterProvider.
3333
type ClusterProviderStatus struct {
34-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
35-
// Important: Run "make" to regenerate code after modifying this file
34+
DeploymentStatus `json:",inline"`
3635
}
3736

3837
// +kubebuilder:object:root=true
@@ -44,8 +43,8 @@ type ClusterProviderStatus struct {
4443
type ClusterProvider struct {
4544
metav1.TypeMeta `json:",inline"`
4645
metav1.ObjectMeta `json:"metadata,omitempty"`
47-
Spec ClusterProviderSpec `json:"spec,omitempty"`
48-
Status DeploymentStatus `json:"status,omitempty"`
46+
Spec ClusterProviderSpec `json:"spec,omitempty"`
47+
Status ClusterProviderStatus `json:"status,omitempty"`
4948
}
5049

5150
// +kubebuilder:object:root=true

api/provider/v1alpha1/platformservice_types.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type PlatformServiceSpec struct {
3131

3232
// PlatformServiceStatus defines the observed state of PlatformService.
3333
type PlatformServiceStatus struct {
34-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
35-
// Important: Run "make" to regenerate code after modifying this file
34+
DeploymentStatus `json:",inline"`
3635
}
3736

3837
// +kubebuilder:object:root=true
@@ -44,8 +43,8 @@ type PlatformServiceStatus struct {
4443
type PlatformService struct {
4544
metav1.TypeMeta `json:",inline"`
4645
metav1.ObjectMeta `json:"metadata,omitempty"`
47-
Spec PlatformServiceSpec `json:"spec,omitempty"`
48-
Status DeploymentStatus `json:"status,omitempty"`
46+
Spec PlatformServiceSpec `json:"spec,omitempty"`
47+
Status PlatformServiceStatus `json:"status,omitempty"`
4948
}
5049

5150
// +kubebuilder:object:root=true

api/provider/v1alpha1/serviceprovider_types.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ type ServiceProviderSpec struct {
3131

3232
// ServiceProviderStatus defines the observed state of ServiceProvider.
3333
type ServiceProviderStatus struct {
34-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
35-
// Important: Run "make" to regenerate code after modifying this file
34+
DeploymentStatus `json:",inline"`
3635
}
3736

3837
// +kubebuilder:object:root=true
@@ -44,8 +43,8 @@ type ServiceProviderStatus struct {
4443
type ServiceProvider struct {
4544
metav1.TypeMeta `json:",inline"`
4645
metav1.ObjectMeta `json:"metadata,omitempty"`
47-
Spec ServiceProviderSpec `json:"spec,omitempty"`
48-
Status DeploymentStatus `json:"status,omitempty"`
46+
Spec ServiceProviderSpec `json:"spec,omitempty"`
47+
Status ServiceProviderStatus `json:"status,omitempty"`
4948
}
5049

5150
// +kubebuilder:object:root=true

api/provider/v1alpha1/zz_generated.deepcopy.go

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

cmd/openmcp-operator/app/run.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import (
3030
)
3131

3232
var setupLog logging.Logger
33-
var allControllers = []string{strings.ToLower(scheduler.ControllerName)}
33+
var allControllers = []string{
34+
strings.ToLower(scheduler.ControllerName),
35+
strings.ToLower(provider.ControllerName),
36+
}
3437

3538
func NewRunCommand(so *SharedOptions) *cobra.Command {
3639
opts := &RunOptions{
@@ -297,13 +300,11 @@ func (o *RunOptions) Run(ctx context.Context) error {
297300
}
298301

299302
// setup deployment controller
300-
// TODO: Can we use a variable/constant/function instead of a hardcoded string for the controller name here?
301-
// TODO: This value has to be added to the allControllers variable too, because I guess we want it to be enabled by default.
302-
if slices.Contains(o.Controllers, strings.ToLower("deploymentcontroller")) {
303+
if slices.Contains(o.Controllers, strings.ToLower(provider.ControllerName)) {
303304
utilruntime.Must(clientgoscheme.AddToScheme(mgr.GetScheme()))
304305
utilruntime.Must(api.AddToScheme(mgr.GetScheme()))
305306

306-
if err = provider.NewDeploymentController().SetupWithManager(mgr, o.ProviderGVKList); err != nil {
307+
if err = provider.NewDeploymentController().SetupWithManager(mgr, o.ProviderGVKList, o.Environment); err != nil {
307308
return fmt.Errorf("unable to setup provider controllers: %w", err)
308309
}
309310
}

internal/controllers/provider/controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78
"time"
89

910
"github.com/openmcp-project/controller-utils/pkg/controller"
@@ -35,10 +36,11 @@ const (
3536
type ProviderReconciler struct {
3637
schema.GroupVersionKind
3738
PlatformClient client.Client
39+
Environment string
3840
}
3941

4042
func (r *ProviderReconciler) ControllerName() string {
41-
return r.GroupVersionKind.String()
43+
return strings.ToLower(r.GroupVersionKind.Kind)
4244
}
4345

4446
func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) {
@@ -144,6 +146,7 @@ func (r *ProviderReconciler) install(
144146
PlatformClient: r.PlatformClient,
145147
Provider: provider,
146148
DeploymentSpec: deploymentSpec,
149+
Environment: r.Environment,
147150
}
148151

149152
if !isInitialized(deploymentStatus) {
@@ -198,6 +201,7 @@ func (r *ProviderReconciler) handleDeleteOperation(ctx context.Context, provider
198201
PlatformClient: r.PlatformClient,
199202
Provider: provider,
200203
DeploymentSpec: nil,
204+
Environment: r.Environment,
201205
}
202206

203207
deploymentStatus.Phase = phaseTerminating
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package provider
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
7+
8+
"github.com/openmcp-project/openmcp-operator/api/provider/v1alpha1"
9+
)
10+
11+
var _ = Describe("Deployment Controller", func() {
12+
13+
Context("Converter", func() {
14+
15+
It("should convert a deploymentStatus into an unstructured and back", func() {
16+
originalStatus := &v1alpha1.DeploymentStatus{
17+
Conditions: nil,
18+
ObservedGeneration: 6,
19+
Phase: phaseProgressing,
20+
}
21+
r := &ProviderReconciler{}
22+
provider := &unstructured.Unstructured{}
23+
provider.Object = map[string]interface{}{}
24+
err := r.deploymentStatusIntoUnstructured(originalStatus, provider)
25+
Expect(err).NotTo(HaveOccurred())
26+
status, err := r.deploymentStatusFromUnstructured(provider)
27+
Expect(err).NotTo(HaveOccurred())
28+
Expect(status).To(Equal(originalStatus))
29+
})
30+
})
31+
})

0 commit comments

Comments
 (0)