Skip to content

Commit

Permalink
fix(apache#4948): Move handling of IntegrationPlatformResource to a s…
Browse files Browse the repository at this point in the history
…eparate operator

Added a separate platformcontroller subcommand to kamel and amended install command as needed.
The platformcontroller works as the operator command but runs an operator that handles just the IntegrationPlatform crd.
  • Loading branch information
valdar committed Jan 31, 2024
1 parent ceaca16 commit 579f251
Show file tree
Hide file tree
Showing 12 changed files with 626 additions and 2 deletions.
89 changes: 89 additions & 0 deletions config/manager/platformcontroller-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# ---------------------------------------------------------------------------
# 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:
name: camel-k-platformcontroller
labels:
app: "camel-k"
camel.apache.org/component: operator
name: camel-k-platformcontroller
app.kubernetes.io/component: operator
app.kubernetes.io/name: camel-k
app.kubernetes.io/version: "2.3.0-SNAPSHOT"
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
name: camel-k-platformcontroller
template:
metadata:
labels:
name: camel-k-platformcontroller
camel.apache.org/component: operator
app: "camel-k"
app.kubernetes.io/component: operator
app.kubernetes.io/name: camel-k
app.kubernetes.io/version: "2.3.0-SNAPSHOT"
spec:
serviceAccountName: camel-k-operator
containers:
- name: camel-k-platformcontroller
image: docker.io/apache/camel-k:2.3.0-SNAPSHOT
imagePullPolicy: IfNotPresent
command:
- kamel
- platformcontroller
ports:
- containerPort: 8080
name: metrics
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OPERATOR_NAME
value: "camel-k-platformcontroller"
- name: OPERATOR_ID
value: "camel-k"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
# NAMESPACE is always the operator namespace, independently of WATCH_NAMESPACE
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 20
periodSeconds: 10
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL

1 change: 1 addition & 0 deletions pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func (o *installCmdOptions) setupEnvVars() {
}
}

// TODO: check this part to add platformcontroller installation
func (o *installCmdOptions) tryInstallViaOLM(
cmd *cobra.Command, clientProvider client.Provider, output *kubernetes.Collection,
) (bool, error) {
Expand Down
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() (*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),
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 579f251

Please sign in to comment.