Skip to content

Commit

Permalink
rebase and post review update
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Oct 15, 2024
1 parent a8b3f64 commit 7d21157
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 59 deletions.
31 changes: 18 additions & 13 deletions internal/controller/validation/common.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// 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.
/*
* 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 validation

Expand Down
35 changes: 20 additions & 15 deletions internal/controller/validation/common_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// 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.
/*
* 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 validation

Expand Down Expand Up @@ -98,8 +103,8 @@ func TestImageStoredInKindRegistry(t *testing.T) {
}

for _, test := range tests {
kindRegistryName = func(ctx context.Context) (string, error) {
return "172.18.0.4:5000", nil
kindRegistryName = func(ctx context.Context) string {
return "172.18.0.4:5000"
}
resolve = func(host string) ([]net.IP, error) {
return []net.IP{net.ParseIP(test.resolvedIp)}, nil
Expand Down
39 changes: 22 additions & 17 deletions internal/controller/validation/image_validator.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// 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.
/*
* 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 validation

Expand Down Expand Up @@ -46,7 +51,7 @@ func (v *imageValidator) Validate(ctx context.Context, client client.Client, son
return err
}
if !equals {
return fmt.Errorf("Workflow, defined in the image %s doesn't match deployment workflow", sonataflow.Spec.PodTemplate.Container.Image)
return fmt.Errorf("Workflow, defined in the image %s doesn't match deployment workflow %s", sonataflow.Spec.PodTemplate.Container.Image, sonataflow.Name)
}
return nil
}
Expand All @@ -72,7 +77,7 @@ func validateImage(ctx context.Context, sonataflow *operatorapi.SonataFlow) (boo
return false, err
}

reader, err := readWorkflowSpecLayer(ref)
reader, err := readWorkflowSpecLayer(ref, sonataflow)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -118,7 +123,7 @@ func kindRegistryImage(sonataflow *operatorapi.SonataFlow) (v1.Image, error) {
return ref, nil
}

func readWorkflowSpecLayer(image v1.Image) (*tar.Reader, error) {
func readWorkflowSpecLayer(image v1.Image, sonataflow *operatorapi.SonataFlow) (*tar.Reader, error) {
layers, err := image.Layers()
if err != nil {
return nil, err
Expand All @@ -131,7 +136,7 @@ func readWorkflowSpecLayer(image v1.Image) (*tar.Reader, error) {
return nil, err
}
}
return nil, fmt.Errorf("Workflow definition was not found in the Docker image")
return nil, fmt.Errorf("Workflow %s definition was not found in the Docker image", sonataflow.Name)
}

func findWorkflowSpecLayer(layer v1.Layer) (*tar.Reader, error) {
Expand Down
33 changes: 19 additions & 14 deletions internal/controller/validation/validator.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Copyright 2024 Apache Software Foundation (ASF)
//
// 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.
/*
* 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 validation

Expand All @@ -28,7 +33,7 @@ type Validator interface {
Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error
}

// validate the SonataFlow object, right now it's only check if workflow is in deployment has image declared as that image
// Validate the SonataFlow object, right now it's only check if workflow is in deployment has image declared as that image
// is the same as the image in the SonataFlow object
func Validate(ctx context.Context, client client.Client, sonataflow *operatorapi.SonataFlow, req ctrl.Request) error {
if sonataflow.HasContainerSpecImage() {
Expand Down

0 comments on commit 7d21157

Please sign in to comment.