Skip to content

Commit

Permalink
Merge pull request #161 from lburgazzoli/gh-158
Browse files Browse the repository at this point in the history
Refactor the current Kaoto Operator to work with Kaoto v2
  • Loading branch information
lburgazzoli authored Jan 16, 2024
2 parents eaa93ec + eaa4332 commit f4b0281
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 417 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
e2e:
uses: ./.github/workflows/e2e.yml
with:
standalone-image: "quay.io/kaotoio/standalone:stable-jvm"
standalone-image: "quay.io/kaotoio/kaoto-app:main"
deploy:
needs:
- e2e
uses: ./.github/workflows/build-and-push.yml
with:
version: "${{ github.ref_name }}-${{ github.sha }}"
standalone-image: "quay.io/kaotoio/standalone:stable-jvm"
standalone-image: "quay.io/kaotoio/kaoto-app:main"
olm: false
tag: main
latest: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
needs:
- build
with:
standalone-image: "quay.io/kaotoio/standalone:stable-jvm"
standalone-image: "quay.io/kaotoio/kaoto-app:main"
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: ./.github/workflows/build-and-push.yml
with:
version: "${{ github.ref_name }}"
standalone-image: "quay.io/kaotoio/standalone:stable-jvm"
standalone-image: "quay.io/kaotoio/kaoto-app:main"
olm: false
tag: "${{ github.ref_name }}"
latest: false
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ endif
IMG ?= ${IMAGE_TAG_BASE}:${IMG_VERSION}

# Kaoto image that is installed by the operator
KAOTO_STANDALONE_IMAGE ?= quay.io/kaotoio/standalone:stable-jvm
KAOTO_APP_IMAGE ?= quay.io/kaotoio/kaoto-app:main

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -68,7 +68,7 @@ else
GOBIN=$(shell go env GOBIN)
endif

GOLDFLAGS = -X 'github.com/kaotoIO/kaoto-operator/pkg/defaults.KaotoStandaloneImage=${KAOTO_STANDALONE_IMAGE}'
GOLDFLAGS = -X 'github.com/kaotoIO/kaoto-operator/pkg/defaults.KaotoAppImage=${KAOTO_APP_IMAGE}'
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
Expand Down
2 changes: 1 addition & 1 deletion apis/designer/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/e2e/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
resources:
- ../default
- ../rbac/backend

patchesJson6902:
- target:
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/kaotoio/kaoto-operator
newTag: latest
newTag: 0.0.9
35 changes: 0 additions & 35 deletions config/rbac/backend/backend_role.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions config/rbac/backend/kustomization.yaml

This file was deleted.

76 changes: 0 additions & 76 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,6 @@ kind: ClusterRole
metadata:
name: kaoto-operator
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- pods/log
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- serviceaccounts
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand All @@ -56,42 +28,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- camel.apache.org
resources:
- integrations
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- camel.apache.org
resources:
- kameletbindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- camel.apache.org
resources:
- kamelets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- designer.kaoto.io
resources:
Expand Down Expand Up @@ -130,18 +66,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterrolebindings
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- route.openshift.io
resources:
Expand Down
3 changes: 2 additions & 1 deletion config/samples/designer_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ metadata:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: kaoto-operator
name: kaoto-test
spec: {}
spec:
ingress: {}
1 change: 0 additions & 1 deletion config/standalone/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
resources:
- ../default
- ../rbac/backend

patchesJson6902:
- target:
Expand Down
8 changes: 0 additions & 8 deletions controllers/designer/kaoto_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func NewKaotoReconciler(manager ctrl.Manager) (*KaotoReconciler, error) {
}

rec.actions = make([]Action, 0)
rec.actions = append(rec.actions, NewRBACAction())
rec.actions = append(rec.actions, NewServiceAction())

if isOpenshift {
Expand All @@ -88,15 +87,8 @@ type KaotoReconciler struct {
// +kubebuilder:rbac:groups=designer.kaoto.io,resources=kaotoes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=designer.kaoto.io,resources=kaotoes/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=designer.kaoto.io,resources=kaotoes/finalizers,verbs=update
// +kubebuilder:rbac:groups=camel.apache.org,resources=kameletbindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=camel.apache.org,resources=kamelets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=camel.apache.org,resources=integrations,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=pods/log,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=clusterrolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="route.openshift.io",resources=routes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="networking.k8s.io",resources=ingresses,verbs=get;list;watch;create;update;patch;delete

Expand Down
46 changes: 2 additions & 44 deletions controllers/designer/kaoto_controller_action_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package designer

import (
"context"
"strings"

"github.com/kaotoIO/kaoto-operator/pkg/controller/client"

Expand All @@ -17,9 +16,6 @@ import (

"github.com/kaotoIO/kaoto-operator/pkg/defaults"

routev1 "github.com/openshift/api/route/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -89,51 +85,14 @@ func (a *deployAction) deploy(ctx context.Context, rr *ReconciliationRequest) er
func (a *deployAction) deployment(ctx context.Context, rr *ReconciliationRequest) (*appsv1ac.DeploymentApplyConfiguration, error) {
image := rr.Kaoto.Spec.Image
if image == "" {
image = defaults.KaotoStandaloneImage
image = defaults.KaotoAppImage
}

labels := Labels(rr.Kaoto)

envs := make([]*corev1ac.EnvVarApplyConfiguration, 0)
envs = append(envs, apply.WithEnvFromField("NAMESPACE", "metadata.namespace"))

// it appears that even with the standalone mode, there are some CORS issues that prevent some endpoint
// to be invoked, the QUARKUS_HTTP_CORS_ORIGINS env must be set.
//
// TODO: investigate why this is needed
// TODO: add support for vanilla ingress
// TODO: ideally the operator could wait to deploy the pod till the ingress/route is deployed and the host
// that should be used for QUARKUS_HTTP_CORS_ORIGINS is known

if rr.Kaoto.Spec.Ingress != nil {
switch {
case rr.Kaoto.Spec.Ingress.Host != "":
// use the provided host if configured so no further lookup would be needed
envs = append(envs, apply.WithEnv("QUARKUS_HTTP_CORS_ORIGINS", rr.Kaoto.Spec.Ingress.Host))

case rr.ClusterType == ClusterTypeOpenShift:
// in case of OpenShift se can leverage the Route.Spec.Host to retrieve the
// right value for the QUARKUS_HTTP_CORS_ORIGINS
//

var in routev1.Route

err := rr.Get(ctx, rr.NamespacedName, &in)
if err != nil && !k8serrors.IsNotFound(err) {
return nil, err
}

if in.Spec.Host != "" {
host := in.Spec.Host
if !strings.HasPrefix(host, "https://") {
host = "https://" + host
}

envs = append(envs, apply.WithEnv("QUARKUS_HTTP_CORS_ORIGINS", host))
}
}
}

resource := appsv1ac.Deployment(rr.Kaoto.Name, rr.Kaoto.Namespace).
WithOwnerReferences(apply.WithOwnerReference(rr.Kaoto)).
WithLabels(Labels(rr.Kaoto)).
Expand All @@ -143,11 +102,10 @@ func (a *deployAction) deployment(ctx context.Context, rr *ReconciliationRequest
WithTemplate(corev1ac.PodTemplateSpec().
WithLabels(labels).
WithSpec(corev1ac.PodSpec().
WithServiceAccountName(rr.Kaoto.Name).
WithContainers(corev1ac.Container().
WithImage(image).
WithImagePullPolicy(corev1.PullAlways).
WithName(KaotoStandaloneName).
WithName(KaotoAppName).
WithPorts(apply.WithPort(KaotoPortType, KaotoPort)).
WithReadinessProbe(apply.WithHTTPProbe(KaotoReadinessProbePath, KaotoPort)).
WithLivenessProbe(apply.WithHTTPProbe(KaotoLivenessProbePath, KaotoPort)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (a *routeAction) route(ctx context.Context, rr *ReconciliationRequest) erro
WithKind("Service").
WithName(rr.Kaoto.Name)).
WithPort(routev1ac.RoutePort().
WithTargetPort(intstr.FromInt(int(KaotoPort)))).
WithTargetPort(intstr.FromInt32(KaotoPort))).
WithTLS(routev1ac.TLSConfig().
WithTermination(routev1.TLSTerminationEdge).
WithInsecureEdgeTerminationPolicy(routev1.InsecureEdgeTerminationPolicyRedirect)))
Expand Down
Loading

0 comments on commit f4b0281

Please sign in to comment.