Skip to content

Commit

Permalink
Merge pull request #7 from treblereel/405_remove_kind_registry_hack
Browse files Browse the repository at this point in the history
Aligned with the upstream changes, kind-registry hack removed and wor…
  • Loading branch information
treblereel authored Oct 9, 2024
2 parents ac78e6b + 1934dae commit 751c3b9
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 257 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ jobs:
make container-build BUILDER=docker IMG=${{ env.OPERATOR_IMAGE_NAME }}
kind load docker-image ${{ env.OPERATOR_IMAGE_NAME }}
- name: Build and Install SonataFlow worfklow test images
run: |
make workflow_test_image_build-and-push
- name: Check Pods
run: |
kubectl version
Expand Down
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,3 @@ deploy-knative:
.PHONY: delete-cluster
delete-cluster: install-kind
kind delete cluster && $(BUILDER) rm -f kind-registry

.PHONY: workflow_test_image_build-and-push
workflow_test_image_build-and-push:
docker build -t localhost:5001/testimage/sonataflow-minimal-example:0.1 ./test/testdata/workflow/docker-image/
docker push localhost:5001/testimage/sonataflow-minimal-example:0.1
docker build --build-arg WORKFLOW_FILE=broken-workflow.sw.json -t localhost:5001/testimage/sonataflow-minimal-example-broken:0.1 ./test/testdata/workflow/docker-image/
docker push localhost:5001/testimage/sonataflow-minimal-example-broken:0.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data:
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/*.jar /deployments/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/app/ /deployments/app/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/src/main/resources/*.sw.* /deployments/app/
EXPOSE 8080
USER 185
Expand Down
1 change: 1 addition & 0 deletions config/manager/SonataFlow-Builder.containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/*.jar /deployments/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/app/ /deployments/app/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/src/main/resources/*.sw.* /deployments/app/

EXPOSE 8080
USER 185
Expand Down
69 changes: 0 additions & 69 deletions internal/controller/validation/image_url_sanitizer.go

This file was deleted.

20 changes: 12 additions & 8 deletions internal/controller/validation/image_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"fmt"
"io"
"net/http"
"regexp"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/serverlessworkflow/sdk-go/v2/model"

operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
"github.com/google/go-cmp/cmp"
Expand All @@ -34,7 +38,7 @@ import (

type imageValidator struct{}

const workflowName = "deployments/app/workflow.sw.json"
var workflowPathRegex = regexp.MustCompile(`^deployments/app/[^/]+\.sw\.(json|yaml)$`)

func (v *imageValidator) Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error {
equals, err := validateImage(ctx, sonataflow)
Expand Down Expand Up @@ -68,7 +72,7 @@ func validateImage(ctx context.Context, sonataflow *operatorapi.SonataFlow) (boo
return false, err
}

reader, err := readWorkflowSpecLayer(ref, workflowName)
reader, err := readWorkflowSpecLayer(ref)
if err != nil {
return false, err
}
Expand All @@ -78,7 +82,7 @@ func validateImage(ctx context.Context, sonataflow *operatorapi.SonataFlow) (boo
return false, err
}

return cmp.Equal(workflowDockerImage, sonataflow.Spec.Flow), nil
return cmp.Equal(workflowDockerImage, sonataflow.Spec.Flow, cmpopts.IgnoreUnexported(model.Transition{})), nil
}

func remoteImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
Expand Down Expand Up @@ -114,23 +118,23 @@ func kindRegistryImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
return ref, nil
}

func readWorkflowSpecLayer(image v1.Image, workflow string) (*tar.Reader, error) {
func readWorkflowSpecLayer(image v1.Image) (*tar.Reader, error) {
layers, err := image.Layers()
if err != nil {
return nil, err
}

for i := len(layers) - 1; i >= 0; i-- {
if reader, err := findWorkflowSpecLayer(layers[i], workflow); err == nil && reader != nil {
if reader, err := findWorkflowSpecLayer(layers[i]); err == nil && reader != nil {
return reader, nil
} else if err != nil {
return nil, err
}
}
return nil, fmt.Errorf("file not found %s in docker image", workflow)
return nil, fmt.Errorf("Workflow definition was not found in the Docker image")
}

func findWorkflowSpecLayer(layer v1.Layer, workflow string) (*tar.Reader, error) {
func findWorkflowSpecLayer(layer v1.Layer) (*tar.Reader, error) {
uncompressedLayer, err := layer.Uncompressed()
if err != nil {
return nil, fmt.Errorf("failed to get uncompressed layer: %v", err)
Expand All @@ -147,7 +151,7 @@ func findWorkflowSpecLayer(layer v1.Layer, workflow string) (*tar.Reader, error)
return nil, fmt.Errorf("error reading tar: %v", err)
}

if header.Typeflag == '0' && header.Name == workflow {
if header.Typeflag == '0' && workflowPathRegex.MatchString(header.Name) {
return tarReader, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

var validators = []Validator{NewImageValidator(), NewImageUrlSanitizer()}
var validators = []Validator{NewImageValidator()}

type Validator interface {
Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error
Expand Down
1 change: 1 addition & 0 deletions operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28206,6 +28206,7 @@ data:
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/*.jar /deployments/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/app/ /deployments/app/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/target/quarkus-app/quarkus/ /deployments/quarkus/
COPY --from=builder --chown=185 /home/kogito/serverless-workflow-project/src/main/resources/*.sw.* /deployments/app/

EXPOSE 8080
USER 185
Expand Down
39 changes: 0 additions & 39 deletions test/e2e/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,45 +137,6 @@ var _ = Describe("Workflow Non-Persistence Use Cases :: ", Label("flows-ephemera
}, 3*time.Minute, time.Second).Should(Succeed())
})

It("should not deploy the Simple Workflow because image contains no workflow definition", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", test.GetPathFromDataDirectory(test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())

By("verifying that the workflow is not in a running state within one minute")
ConsistentlyWithOffset(1, func() bool {
return verifyWorkflowIsInRunningState("simple", targetNamespace)
}, 1*time.Minute, 10*time.Second).Should(BeFalse(), "Workflow unexpectedly reached the running state")

EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", test.GetPathFromDataDirectory(test.SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})

It("should not deploy the Simple Workflow because image contains broken (not equals to flow from yaml) workflow definition", func() {
By("creating an instance of the SonataFlow Operand(CR)")
EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "apply", "-f", test.GetPathFromDataDirectory(test.SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())

By("verifying that the workflow is not in a running state within one minute")
ConsistentlyWithOffset(1, func() bool {
return verifyWorkflowIsInRunningState("simple", targetNamespace)
}, 1*time.Minute, 10*time.Second).Should(BeFalse(), "Workflow unexpectedly reached the running state")

EventuallyWithOffset(1, func() error {
cmd := exec.Command("kubectl", "delete", "-f", test.GetPathFromDataDirectory(test.SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow), "-n", targetNamespace)
_, err := utils.Run(cmd)
return err
}, 3*time.Minute, time.Second).Should(Succeed())
})
})

})
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
container:
# TODO use docker.io/apache/incubator-kie-sonataflow-minimal-example:latest
# when we complete https://github.com/apache/incubator-kie-kogito-serverless-operator/issues/504
image: kind-registry:5000/testimage/sonataflow-minimal-example:0.1
image: quay.io/kiegroup/sonataflow-minimal-example:latest
flow:
start: HelloWorld
states:
Expand Down
17 changes: 0 additions & 17 deletions test/testdata/workflow/docker-image/Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions test/testdata/workflow/docker-image/broken-workflow.sw.json

This file was deleted.

18 changes: 0 additions & 18 deletions test/testdata/workflow/docker-image/workflow.sw.json

This file was deleted.

7 changes: 2 additions & 5 deletions test/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ const (
sonataFlowBuilderConfig = "sonataflow-operator-builder-config_v1_configmap.yaml"
sonataFlowBuildSucceed = "sonataflow.org_v1alpha08_sonataflowbuild.yaml"
knativeDefaultBrokerCR = "knative_default_broker.yaml"

SonataFlowSimpleOpsYamlCRImageContainsNoWorkflow = "sonataflow.org_v1alpha08_sonataflow-simpleops-no-workflow-in-image.yaml"
SonataFlowSimpleOpsYamlCRImageContainsBrokenWorkflow = "sonataflow.org_v1alpha08_sonataflow-simpleops-broken-workflow-in-image.yaml"
e2eSamples = "test/testdata/"
manifestsPath = "bundle/manifests/"
e2eSamples = "test/testdata/"
manifestsPath = "bundle/manifests/"
)

var projectDir = ""
Expand Down

0 comments on commit 751c3b9

Please sign in to comment.