forked from apache/incubator-kie-kogito-serverless-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Issue apache#319 - Rename prod profile to preview (apache#414)
* Fix Issue apache#319 - Rename prod profile to preview Signed-off-by: Ricardo Zanini <[email protected]> * Renaming profile after rebase Signed-off-by: Ricardo Zanini <[email protected]> --------- Signed-off-by: Ricardo Zanini <[email protected]>
- Loading branch information
1 parent
0699a93
commit ca5744d
Showing
44 changed files
with
275 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ | |
/.idea/ | ||
/.vscode/ | ||
/target/ | ||
|
||
e2e-test-report.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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. | ||
|
||
package gitops | ||
|
||
import "github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/preview" | ||
|
||
// Aliases to preview profile package to avoid cluttering this package with references to preview profile. | ||
// It makes easier to maintain and understand where it comes the references. | ||
|
||
var newDeploymentReconciler = preview.NewDeploymentReconciler | ||
var newObjectEnsurers = preview.NewObjectEnsurers | ||
|
||
type objectEnsurers = preview.ObjectEnsurers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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. | ||
|
||
package gitops | ||
|
||
import ( | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/api/metadata" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/discovery" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/record" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var _ profiles.ProfileReconciler = &gitOpsProfile{} | ||
|
||
type gitOpsProfile struct { | ||
common.Reconciler | ||
} | ||
|
||
// NewProfileForOpsReconciler creates an alternative prod profile that won't require to build the workflow image in order to deploy | ||
// the workflow application. It assumes that the image has been built somewhere else. | ||
func NewProfileForOpsReconciler(client client.Client, cfg *rest.Config, recorder record.EventRecorder) profiles.ProfileReconciler { | ||
support := &common.StateSupport{ | ||
C: client, | ||
Cfg: cfg, | ||
Catalog: discovery.NewServiceCatalogForConfig(client, cfg), | ||
Recorder: recorder, | ||
} | ||
// the reconciliation state machine | ||
stateMachine := common.NewReconciliationStateMachine( | ||
&ensureBuildSkipped{StateSupport: support}, | ||
&followDeployWorkflowState{StateSupport: support, ensurers: newObjectEnsurers(support)}, | ||
) | ||
reconciler := &gitOpsProfile{ | ||
Reconciler: common.NewReconciler(support, stateMachine), | ||
} | ||
|
||
return reconciler | ||
} | ||
|
||
func (p gitOpsProfile) GetProfile() metadata.ProfileType { | ||
return metadata.GitOpsProfile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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. | ||
|
||
package gitops | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/apache/incubator-kie-kogito-serverless-operator/api" | ||
operatorapi "github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08" | ||
"github.com/apache/incubator-kie-kogito-serverless-operator/test" | ||
"github.com/stretchr/testify/assert" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/client-go/rest" | ||
clientruntime "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func Test_Reconciler_ProdOps(t *testing.T) { | ||
workflow := test.GetBaseSonataFlowWithProdOpsProfile(t.Name()) | ||
workflow.Spec.PodTemplate.PodSpec.InitContainers = append(workflow.Spec.PodTemplate.PodSpec.InitContainers, corev1.Container{ | ||
Name: "check-postgres", | ||
Image: "registry.access.redhat.com/ubi9/ubi-micro:latest", | ||
Command: []string{"sh", "-c", "until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo \"Waiting for postgres server\"; sleep 3; done;"}, | ||
}) | ||
client := test.NewSonataFlowClientBuilder(). | ||
WithRuntimeObjects(workflow). | ||
WithStatusSubresource(workflow, &operatorapi.SonataFlowBuild{}).Build() | ||
result, err := NewProfileForOpsReconciler(client, &rest.Config{}, test.NewFakeRecorder()).Reconcile(context.TODO(), workflow) | ||
assert.NoError(t, err) | ||
|
||
assert.NotNil(t, result.RequeueAfter) | ||
assert.True(t, workflow.Status.GetCondition(api.BuiltConditionType).IsFalse()) | ||
assert.Equal(t, api.BuildSkippedReason, workflow.Status.GetCondition(api.BuiltConditionType).Reason) | ||
// We need the deployment controller to tell us that the workflow is ready | ||
// Since we don't have it in a mocked env, the result must be ready == false | ||
assert.False(t, workflow.Status.IsReady()) | ||
|
||
// Reconcile again to run the deployment handler | ||
result, err = NewProfileForOpsReconciler(client, &rest.Config{}, test.NewFakeRecorder()).Reconcile(context.TODO(), workflow) | ||
assert.NoError(t, err) | ||
|
||
// Let's check for the right creation of the workflow (one CM volume, one container with a custom image) | ||
deployment := &appsv1.Deployment{} | ||
err = client.Get(context.TODO(), clientruntime.ObjectKeyFromObject(workflow), deployment) | ||
assert.NoError(t, err) | ||
|
||
assert.Len(t, deployment.Spec.Template.Spec.Volumes, 1) | ||
assert.Len(t, deployment.Spec.Template.Spec.Containers, 1) | ||
assert.Len(t, deployment.Spec.Template.Spec.InitContainers, 1) | ||
assert.Len(t, deployment.Spec.Template.Spec.Containers[0].VolumeMounts, 1) | ||
|
||
assert.NotNil(t, deployment.ObjectMeta) | ||
assert.NotNil(t, deployment.ObjectMeta.Labels) | ||
assert.Equal(t, deployment.ObjectMeta.Labels, map[string]string{"test": "test", "app": "simple", "sonataflow.org/workflow-app": "simple"}) | ||
} |
Oops, something went wrong.