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

[KOGITO-9218] - Implement Conditions API and review SonataFlowPlatform #214

Merged
merged 5 commits into from
Aug 9, 2023
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ run: manifests generate ## Run a controller from your host.

.PHONY: debug
debug: build-4-debug ## Run a controller from your host from binary
./bin/manager
./bin/manager -v=2

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
Expand Down
16 changes: 16 additions & 0 deletions api/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package api

import (
"fmt"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -102,3 +104,17 @@ func (c *Condition) GetMessage() string {
}
return c.Message
}

func (c *Condition) String() string {
if c == nil {
return ""
}
str := fmt.Sprintf("Condition %s status is %s", c.Type, c.Status)
if len(c.Reason) > 0 {
str += fmt.Sprintf(". [Reason] %s", c.Reason)
}
if len(c.Message) > 0 {
str += fmt.Sprintf(". [Message] %s", c.Message)
}
return str
}
8 changes: 8 additions & 0 deletions api/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func (s *Status) GetCondition(t ConditionType) *Condition {
return nil
}

func (s *Status) String() string {
str := ""
for _, c := range s.Conditions {
str += c.String() + "\n"
}
return str
}

func (s *Status) setConditions(c Conditions) {
s.Conditions = c
}
Expand Down
102 changes: 102 additions & 0 deletions api/v1alpha08/sonataflowplatform_build_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 v1alpha08

import (
"strconv"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Describes the general build specification for this platform. Specific for build scenarios.
type BuildPlatformSpec struct {
// Describes a build template for building workflows. Base for the internal SonataFlowBuild resource.
Template BuildTemplate `json:"template,omitempty"`
// Describes the platform configuration for building workflows.
Config BuildPlatformConfig `json:"config,omitempty"`
}

// Describes the configuration for building in the given platform
type BuildPlatformConfig struct {
// a base image that can be used as base layer for all images.
// It can be useful if you want to provide some custom base image with further utility software
BaseImage string `json:"baseImage,omitempty"`
// how much time to wait before time out the build process
Timeout *metav1.Duration `json:"timeout,omitempty"`
// BuildStrategy to use to build workflows in the platform.
// Usually, the operator elect the strategy based on the platform.
// Note that this field might be read only in certain scenarios.
BuildStrategy BuildStrategy `json:"strategy,omitempty"`
// BuildStrategyOptions additional options to add to the build strategy.
// See https://sonataflow.org/serverlessworkflow/main/cloud/operator/build-and-deploy-workflows.html
BuildStrategyOptions map[string]string `json:"strategyOptions,omitempty"`
// Registry the registry where to publish the built image
Registry RegistrySpec `json:"registry,omitempty"`
}

// GetTimeout returns the specified duration or a default one
func (b *BuildPlatformConfig) GetTimeout() metav1.Duration {
if b.Timeout == nil {
return metav1.Duration{}
}
return *b.Timeout
}

// IsStrategyOptionEnabled return whether the BuildStrategyOptions is enabled or not
func (b *BuildPlatformConfig) IsStrategyOptionEnabled(option string) bool {
if enabled, ok := b.BuildStrategyOptions[option]; ok {
res, err := strconv.ParseBool(enabled)
if err != nil {
return false
}
return res
}
return false
}

func (b *BuildPlatformConfig) IsStrategyOptionEmpty(option string) bool {
if v, ok := b.BuildStrategyOptions[option]; ok {
return len(v) == 0
}
return false
}

// RegistrySpec provides the configuration for the container registry
type RegistrySpec struct {
// if the container registry is insecure (ie, http only)
Insecure bool `json:"insecure,omitempty"`
// the URI to access
Address string `json:"address,omitempty"`
// the secret where credentials are stored
Secret string `json:"secret,omitempty"`
// the configmap which stores the Certificate Authority
CA string `json:"ca,omitempty"`
// the registry organization
Organization string `json:"organization,omitempty"`
}

type BuildStrategy string

const (
// OperatorBuildStrategy uses the operator builder to perform the workflow build
// E.g. on Minikube or Kubernetes the container-builder strategies
OperatorBuildStrategy BuildStrategy = "operator"
// PlatformBuildStrategy uses the cluster to perform the build.
// E.g. on OpenShift, BuildConfig.
PlatformBuildStrategy BuildStrategy = "platform"

// In the future we can have "custom" which will delegate the build to an external actor provided by the administrator
// See https://issues.redhat.com/browse/KOGITO-9084
)
21 changes: 21 additions & 0 deletions api/v1alpha08/sonataflowplatform_devmode_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 v1alpha08

// DevModePlatformSpec describes the devmode configuration for the given platform.
type DevModePlatformSpec struct {
// Base image to run the Workflow in dev mode instead of the operator's default.
BaseImage string `json:"baseImage,omitempty"`
}
Loading
Loading