Skip to content

Commit f3299b2

Browse files
authored
feat: remote deployment (full) (#343)
--------- On-behalf-of: @SAP angel.kafazov@sap.com Signed-off-by: Angel Kafazov <akafazov@cst-bg.net>
1 parent 57388d5 commit f3299b2

77 files changed

Lines changed: 7533 additions & 1339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@ test/e2e/kind/certs/
4242
*.key
4343
**/__debug_bin*
4444
gha-logs.txt
45+
*.kubeconfig
46+
debug
47+
.cursor/*
4548
test/e2e/kind/kind-testcluster.kubeconfig

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ COPY internal/ internal/
2323
COPY pkg/ pkg/
2424
COPY manifests/ manifests/
2525

26+
COPY gotemplates/ gotemplates/
27+
2628
# Build
2729
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags '-w -s' -o manager main.go
2830

@@ -34,6 +36,6 @@ ENV USER_UID=1001
3436
ENV GROUP_UID=1001
3537
COPY --from=builder --chown=${USER_UID}:${GROUP_UID} /workspace/manager /operator/manager
3638
COPY --from=builder --chown=${USER_UID}:${GROUP_UID} /workspace/manifests /operator/manifests
37-
39+
COPY --from=builder --chown=${USER_UID}:${GROUP_UID} /workspace/gotemplates /operator/gotemplates
3840
USER ${USER_UID}:${GROUP_UID}
3941
ENTRYPOINT ["/operator/manager"]

README.md

Lines changed: 124 additions & 144 deletions
Large diffs are not rendered by default.

api/v1alpha1/platformmesh_types.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ import (
2323

2424
// PlatformMeshSpec defines the desired state of PlatformMesh
2525
type PlatformMeshSpec struct {
26-
Exposure *ExposureConfig `json:"exposure,omitempty"`
27-
Kcp Kcp `json:"kcp,omitempty"`
28-
Values apiextensionsv1.JSON `json:"values,omitempty"`
29-
OCM *OCMConfig `json:"ocm,omitempty"`
30-
FeatureToggles []FeatureToggle `json:"featureToggles,omitempty"`
31-
InfraValues apiextensionsv1.JSON `json:"infraValues,omitempty"`
32-
Wait *WaitConfig `json:"wait,omitempty"`
26+
Exposure *ExposureConfig `json:"exposure,omitempty"`
27+
Kcp Kcp `json:"kcp,omitempty"`
28+
Values apiextensionsv1.JSON `json:"values,omitempty"`
29+
OCM *OCMConfig `json:"ocm,omitempty"`
30+
FeatureToggles []FeatureToggle `json:"featureToggles,omitempty"`
31+
InfraValues apiextensionsv1.JSON `json:"infraValues,omitempty"`
32+
Wait *WaitConfig `json:"wait,omitempty"`
33+
ProfileConfigMap *ConfigMapReference `json:"profileConfigMap,omitempty"`
34+
}
35+
36+
type ConfigMapReference struct {
37+
// +kubebuilder:validation:MinLength=1
38+
Name string `json:"name"`
39+
// +optional
40+
Namespace string `json:"namespace,omitempty"`
3341
}
3442

3543
type WaitConfig struct {
@@ -79,24 +87,17 @@ type Kcp struct {
7987
ProviderConnections []ProviderConnection `json:"providerConnections,omitempty"`
8088
ExtraProviderConnections []ProviderConnection `json:"extraProviderConnections,omitempty"`
8189
ExtraDefaultAPIBindings []DefaultAPIBindingConfiguration `json:"extraDefaultAPIBindings,omitempty"`
82-
// ExtraWorkspaces allows declaring additional workspaces that the operator will create.
8390
// +optional
8491
ExtraWorkspaces []WorkspaceDeclaration `json:"extraWorkspaces,omitempty"`
8592
}
8693

87-
// WorkspaceDeclaration defines a workspace to be created by the operator.
8894
type WorkspaceDeclaration struct {
89-
// Path is the full logical path of the workspace to be created (e.g., "root:orgs:my-workspace").
90-
Path string `json:"path"`
91-
// Type defines the WorkspaceType for the new workspace.
95+
Path string `json:"path"`
9296
Type WorkspaceTypeReference `json:"type"`
9397
}
9498

95-
// WorkspaceTypeReference specifies the type of a workspace.
9699
type WorkspaceTypeReference struct {
97-
// Name is the name of the WorkspaceType.
98100
Name string `json:"name"`
99-
// Path is the logical cluster path where the WorkspaceType is defined.
100101
Path string `json:"path"`
101102
}
102103

@@ -127,10 +128,8 @@ type KCPAPIVersionKindRef struct {
127128
}
128129

129130
type SecretReference struct {
130-
// name is unique within a namespace to reference a secret resource.
131131
// +optional
132132
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
133-
// namespace defines the space within which the secret name must be unique.
134133
// +optional
135134
Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
136135
}

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/operator.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,25 @@ package cmd
1919
import (
2020
"context"
2121
"crypto/tls"
22+
"fmt"
2223
"net/http"
2324
"os"
2425

2526
pmcontext "github.com/platform-mesh/golang-commons/context"
2627
"github.com/spf13/cobra"
28+
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2729
_ "k8s.io/client-go/plugin/pkg/client/auth"
2830
"k8s.io/client-go/rest"
2931
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/client"
3033
"sigs.k8s.io/controller-runtime/pkg/healthz"
3134
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3235
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
3336

3437
"github.com/platform-mesh/golang-commons/traces"
35-
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
3638

3739
"github.com/platform-mesh/platform-mesh-operator/internal/controller"
40+
"github.com/platform-mesh/platform-mesh-operator/pkg/subroutines"
3841
)
3942

4043
var operatorCmd = &cobra.Command{
@@ -86,6 +89,16 @@ func RunController(_ *cobra.Command, _ []string) { // coverage-ignore
8689
log.Info().Msg("Starting manager")
8790

8891
restCfg := ctrl.GetConfigOrDie()
92+
if operatorCfg.RemoteRuntime.IsEnabled() {
93+
setupLog.Info("Remote PlatformMesh reconciliation enabled, kubeconfig: " + operatorCfg.RemoteRuntime.Kubeconfig)
94+
var err error
95+
_, restCfg, err = subroutines.GetClientAndRestConfig(operatorCfg.RemoteRuntime.Kubeconfig)
96+
if err != nil {
97+
setupLog.Error(err, "unable to create PlatformMesh client")
98+
os.Exit(1)
99+
}
100+
}
101+
setupLog.Info(fmt.Sprintf("PlatformMesh Host: %s", restCfg.Host))
89102
restCfg.Wrap(func(rt http.RoundTripper) http.RoundTripper {
90103
return otelhttp.NewTransport(rt)
91104
})
@@ -117,9 +130,28 @@ func RunController(_ *cobra.Command, _ []string) { // coverage-ignore
117130
os.Exit(1)
118131
}
119132

120-
log.Info().Msg("Manager successfully started")
133+
log.Info().Msg("Manager successfully created")
134+
135+
restCfgInfra := ctrl.GetConfigOrDie()
136+
restCfgInfra.Wrap(func(rt http.RoundTripper) http.RoundTripper {
137+
return otelhttp.NewTransport(rt)
138+
})
139+
clientInfra, err := client.New(restCfgInfra, client.Options{Scheme: subroutines.GetClientScheme()})
140+
if err != nil {
141+
setupLog.Error(err, "unable to create Infra client")
142+
os.Exit(1)
143+
}
144+
if operatorCfg.RemoteInfra.IsEnabled() {
145+
var infraErr error
146+
clientInfra, _, infraErr = subroutines.GetClientAndRestConfig(operatorCfg.RemoteInfra.Kubeconfig)
147+
if infraErr != nil {
148+
setupLog.Error(infraErr, "unable to create Infra client")
149+
os.Exit(1)
150+
}
151+
}
152+
imageVersionStore := subroutines.NewImageVersionStore()
121153

122-
pmReconciler, err := controller.NewPlatformMeshReconciler(mgr, &operatorCfg, defaultCfg, operatorCfg.WorkspaceDir)
154+
pmReconciler, err := controller.NewPlatformMeshReconciler(mgr, &operatorCfg, defaultCfg, operatorCfg.WorkspaceDir, clientInfra, imageVersionStore)
123155
if err != nil {
124156
setupLog.Error(err, "unable to create PlatformMesh reconciler")
125157
os.Exit(1)
@@ -129,16 +161,15 @@ func RunController(_ *cobra.Command, _ []string) { // coverage-ignore
129161
os.Exit(1)
130162
}
131163

132-
resourceReconciler, err := controller.NewResourceReconciler(mgr, &operatorCfg)
164+
resourceReconciler, err := controller.NewResourceReconciler(mgr, &operatorCfg, clientInfra, imageVersionStore)
133165
if err != nil {
134166
setupLog.Error(err, "unable to create Resource reconciler")
135167
os.Exit(1)
136168
}
137169
if err := resourceReconciler.SetupWithManager(mgr, defaultCfg); err != nil {
138-
setupLog.Error(err, "unable to create controller", "controller", "PlatformMesh")
170+
setupLog.Error(err, "unable to create controller", "controller", "Resource")
139171
os.Exit(1)
140172
}
141-
142173
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
143174
setupLog.Error(err, "unable to set up health check")
144175
os.Exit(1)
@@ -152,4 +183,5 @@ func RunController(_ *cobra.Command, _ []string) { // coverage-ignore
152183
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
153184
log.Fatal().Err(err).Msg("problem running manager")
154185
}
186+
155187
}

config/crd/core.platform-mesh.io_platformmeshes.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ spec:
235235
type: string
236236
type: object
237237
type: object
238+
profileConfigMap:
239+
description: ProfileConfigMap references a ConfigMap containing profile
240+
configuration for this PlatformMesh instance.
241+
properties:
242+
name:
243+
description: Name is the name of the ConfigMap.
244+
minLength: 1
245+
type: string
246+
namespace:
247+
description: Namespace is the namespace of the ConfigMap. If not
248+
specified, defaults to the PlatformMesh resource's namespace.
249+
type: string
250+
required:
251+
- name
252+
type: object
238253
values:
239254
x-kubernetes-preserve-unknown-fields: true
240255
wait:

config/rbac/argocd_role.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: platform-mesh-operator-argocd-role
6+
namespace: argocd
7+
rules:
8+
- apiGroups:
9+
- argoproj.io
10+
resources:
11+
- appprojects
12+
verbs:
13+
- create
14+
- delete
15+
- get
16+
- list
17+
- patch
18+
- update
19+
- watch
20+
- apiGroups:
21+
- argoproj.io
22+
resources:
23+
- applications
24+
verbs:
25+
- create
26+
- delete
27+
- get
28+
- list
29+
- patch
30+
- update
31+
- watch
32+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: platform-mesh-operator
7+
app.kubernetes.io/managed-by: kustomize
8+
name: platform-mesh-operator-argocd-rolebinding
9+
namespace: argocd
10+
roleRef:
11+
apiGroup: rbac.authorization.k8s.io
12+
kind: Role
13+
name: platform-mesh-operator-argocd-role
14+
subjects:
15+
- kind: ServiceAccount
16+
name: platform-mesh-operator
17+
namespace: platform-mesh-system
18+

config/rbac/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ resources:
2424
# if you do not want those helpers be installed with your Project.
2525
- platform-mesh_editor_role.yaml
2626
- platform-mesh_viewer_role.yaml
27+
# RBAC for ArgoCD namespace (required for AppProject resources)
28+
- argocd_role.yaml
29+
- argocd_role_binding.yaml
2730

0 commit comments

Comments
 (0)