Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [KOGITO-8945] Defined a Traits API to customize a Kubernetes Service #87

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions api/trait/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 Red Hat, Inc. and/or its affiliates
//
// Licensed 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 trait

// The Service trait exposes the integration with a Service resource so that it can be accessed by other applications
// (or integrations) in the same namespace.

type ServiceTrait struct {
// To automatically detect from the code if a Service needs to be created.
Auto *bool `property:"auto" json:"auto,omitempty"`
// The type of service to be used, either 'ClusterIP', 'NodePort', or 'LoadBalancer'.
// +kubebuilder:validation:Enum=ClusterIP;NodePort;LoadBalancer
Type *ServiceType `property:"type" json:"type,omitempty"`
}

type ServiceType string

const (
// ServiceTypeClusterIP means a service will only be accessible inside the
// cluster, via the cluster IP.
ServiceTypeClusterIP ServiceType = "ClusterIP"

// ServiceTypeNodePort means a service will be exposed on one port of
// every node, in addition to 'ClusterIP' type.
ServiceTypeNodePort ServiceType = "NodePort"

// ServiceTypeLoadBalancer means a service will be exposed via an
// external load balancer (if the cloud provider supports it), in addition
// to 'NodePort' type.
ServiceTypeLoadBalancer ServiceType = "LoadBalancer"
)
13 changes: 11 additions & 2 deletions api/v1alpha08/kogitoserverlessplatform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package v1alpha08

import (
"github.com/kiegroup/container-builder/api"
"github.com/kiegroup/kogito-serverless-operator/api/trait"
"github.com/kiegroup/kogito-serverless-operator/container-builder/api"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kiegroup/kogito-serverless-operator/container-builder/api"
)

// ConfigurationSpecType is used to define the enum values of the supported types for ConfigurationSpec
Expand Down Expand Up @@ -87,8 +88,16 @@ type KogitoServerlessPlatformSpec struct {
BuildPlatform api.PlatformBuildSpec `json:"platform,omitempty"`
// Configuration list of configuration properties to be attached to all the Workflow built from this Platform
Configuration ConfigurationSpec `json:"configuration,omitempty"`

// DevBaseImage, optional, used for the dev profile only
DevBaseImage string `json:"devBaseImage,omitempty"`
// Trait list of traits properties attached to all the Workflow built from this Platform
amadhusu marked this conversation as resolved.
Show resolved Hide resolved
Traits Traits `json:"traits,omitempty"`
spolti marked this conversation as resolved.
Show resolved Hide resolved
}

type Traits struct {
// The configuration of Service trait
Service *trait.ServiceTrait `property:"service" json:"service,omitempty"`
}

// PlatformPhase is the phase of a Platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ spec:
description: how much time to wait before time out the build process
type: string
type: object
traits:
description: Trait is list of trait properties attached to all Workflows
built with Platform
properties:
service:
description: The configuration of Service trait
properties:
auto:
description: To automatically detect from the code if a Service
needs to be created.
type: boolean
type:
description: The type of service to be used, either 'ClusterIP',
'NodePort', or 'LoadBalancer'.
enum:
- ClusterIP
- NodePort
- LoadBalancer
type: string
type: object
type: object
type: object
status:
description: KogitoServerlessPlatformStatus defines the observed state
Expand Down Expand Up @@ -528,6 +549,27 @@ spec:
description: how much time to wait before time out the build process
type: string
type: object
traits:
description: Trait is list of trait properties attached to all Workflows
built with Platform
properties:
service:
description: The configuration of Service trait
properties:
auto:
description: To automatically detect from the code if a Service
needs to be created.
type: boolean
type:
description: The type of service to be used, either 'ClusterIP',
'NodePort', or 'LoadBalancer'.
enum:
- ClusterIP
- NodePort
- LoadBalancer
type: string
type: object
type: object
version:
description: Version the Kogito Serverless operator version controlling
this Platform
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: sw.kogito.kie.org/v1alpha08
kind: KogitoServerlessPlatform
metadata:
name: kogito-workflow-platform
spec:
cluster: kubernetes
platform:
registry:
address: quay.io/kiegroup
secret: regcred
traits:
service:
auto: true
type: NodePort
21 changes: 21 additions & 0 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ var _ = Describe("Kogito Serverless Operator", Ordered, func() {
return err
}, time.Minute, time.Second).Should(Succeed())
})

It("should successfully honor service Trait", func() {

By("creating the service if auto is set to true")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", filepath.Join(projectDir,
"config/samples/"+test.KogitoServerlessPlatformWithTraitCR), "-n", namespace)
_, err := utils.Run(cmd)
return err
}, time.Minute, time.Second).Should(Succeed())

By("check the workflow is in running state")
EventuallyWithOffset(1, verifyWorkflowIsInRunningState, 5*time.Minute, 30*time.Second).Should(BeTrue())

EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", filepath.Join(projectDir,
"config/samples/"+test.KogitoServerlessPlatformWithTraitCR), "-n", namespace)
_, err := utils.Run(cmd)
return err
}, time.Minute, time.Second).Should(Succeed())
})
})
})

Expand Down
1 change: 1 addition & 0 deletions test/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
KogitoServerlessPlatformYamlCR = "sw.kogito_v1alpha08_kogitoserverlessplatform.yaml"
KogitoServerlessPlatformWithBaseImageYamlCR = "sw.kogito_v1alpha08_kogitoserverlessplatformWithBaseImage.yaml"
KogitoServerlessPlatformWithDevBaseImageYamlCR = "sw.kogito_v1alpha08_kogitoserverlessplatformWithDevBaseImage.yaml"
KogitoServerlessPlatformWithTraitCR = "sw.kogito_v1alpha08_kogitoserverlessplatform_withTrait.yaml"
)

func GetKogitoServerlessWorkflow(path string, namespace string) *operatorapi.KogitoServerlessWorkflow {
Expand Down