Skip to content

Commit

Permalink
fix(apache#4948): Move handling of IntegrationPlatform CR to a separa…
Browse files Browse the repository at this point in the history
…te operator.

Add a separate platformcontroller subcommand to kamel, amend install command and other installations (OLM, kustomize, helm) as needed.
The platformcontroller works as the operator command but runs an operator that handles just the IntegrationPlatform crd;
the operator dose not manage IntegrationPlatform crd any more.
  • Loading branch information
valdar committed May 8, 2024
1 parent 6da16e2 commit fa997a3
Show file tree
Hide file tree
Showing 18 changed files with 877 additions and 57 deletions.
110 changes: 65 additions & 45 deletions e2e/advanced/operator_metrics_test.go

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,14 @@ func ConsoleCLIDownload(t *testing.T, ctx context.Context, name string) func() *
}

func OperatorPod(t *testing.T, ctx context.Context, ns string) func() *corev1.Pod {
return componentPod(t, ctx, ns, "operator")
}

func PlatformcontrollerPod(t *testing.T, ctx context.Context, ns string) func() *corev1.Pod {
return componentPod(t, ctx, ns, "platformcontroller")
}

func componentPod(t *testing.T, ctx context.Context, ns string, componentLabelValue string) func() *corev1.Pod {
return func() *corev1.Pod {
lst := corev1.PodList{
TypeMeta: metav1.TypeMeta{
Expand All @@ -2430,7 +2438,7 @@ func OperatorPod(t *testing.T, ctx context.Context, ns string) func() *corev1.Po
if err := TestClient(t).List(ctx, &lst,
ctrl.InNamespace(ns),
ctrl.MatchingLabels{
"camel.apache.org/component": "operator",
"camel.apache.org/component": componentLabelValue,
}); err != nil {
failTest(t, err)
}
Expand Down
111 changes: 111 additions & 0 deletions helm/camel-k/templates/platformcontroller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------

apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: camel-k
camel.apache.org/component: platformcontroller
{{- include "camel-k.labels" . | nindent 4 }}
{{- with .Values.operator.annotations }}
annotations:
{{ toYaml . | nindent 4 }}
{{- end }}
name: camel-k-platformcontroller
spec:
replicas: 1
selector:
matchLabels:
name: camel-k-platformcontroller
strategy:
type: Recreate
template:
metadata:
labels:
app: camel-k
camel.apache.org/component: platformcontroller
name: camel-k-platformcontroller
spec:
{{- if .Values.operator.imagePullSecrets }}
imagePullSecrets:
{{ toYaml .Values.operator.imagePullSecrets | indent 8 }}
{{- end }}

containers:
- command:
- kamel
- platformcontroller
env:
- name: WATCH_NAMESPACE
{{- if eq .Values.operator.global "false" }}
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- else }}
value: ""
{{- end }}
- name: LOG_LEVEL
value: {{ .Values.operator.logLevel }}
- name: OPERATOR_NAME
value: camel-k-platformcontroller
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KAMEL_OPERATOR_ID
value: {{ .Values.operator.operatorId }}
image: {{ .Values.operator.image }}
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 20
periodSeconds: 10
name: camel-k-platformcontroller
ports:
- containerPort: 8080
name: metrics
{{- with .Values.operator.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.operator.securityContext }}
{{- with .Values.operator.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- else }}
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
{{- end }}
serviceAccountName: camel-k-operator
{{- with .Values.operator.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
68 changes: 68 additions & 0 deletions pkg/cmd/platformcontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/apache/camel-k/v2/pkg/cmd/platformcontroller"
"github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/defaults"
"github.com/spf13/cobra"
)

const platformcontrollerCommand = "platformcontroller"

func newCmdPlatformController(rootCmdOptions *RootCmdOptions) (*cobra.Command, *platformcontrollerCmdOptions) {
options := platformcontrollerCmdOptions{}

cmd := cobra.Command{
Use: "platformcontroller",
Short: "Run the Camel K platform controller",
Long: `Run the Camel K platform controller`,
Hidden: true,
PreRunE: decode(&options, rootCmdOptions.Flags),
Run: options.run,
}

cmd.Flags().Int32("health-port", 8081, "The port of the health endpoint")
cmd.Flags().Int32("monitoring-port", 8080, "The port of the metrics endpoint")
cmd.Flags().Bool("leader-election", true, "Use leader election")
cmd.Flags().String("leader-election-id", "", "Use the given ID as the leader election Lease name")

return &cmd, &options
}

type platformcontrollerCmdOptions struct {
HealthPort int32 `mapstructure:"health-port"`
MonitoringPort int32 `mapstructure:"monitoring-port"`
LeaderElection bool `mapstructure:"leader-election"`
LeaderElectionID string `mapstructure:"leader-election-id"`
}

func (o *platformcontrollerCmdOptions) run(_ *cobra.Command, _ []string) {

leaderElectionID := o.LeaderElectionID
if leaderElectionID == "" {
if defaults.OperatorID() != "" {
leaderElectionID = platform.GetPlatformControllerLockName(defaults.OperatorID())
} else {
leaderElectionID = platform.PlatformControllerLockName
}
}

platformcontroller.Run(o.HealthPort, o.MonitoringPort, o.LeaderElection, leaderElectionID)
}
Loading

0 comments on commit fa997a3

Please sign in to comment.