-
Notifications
You must be signed in to change notification settings - Fork 4
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
Improve current state #231
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70791cd
refactor: move functions
ChrisKujawa c16f000
test: write tests for statefulset
ChrisKujawa d42ed12
feat: support network patch for saas
ChrisKujawa e2fe8da
refactor: extract getDeployment
ChrisKujawa 41d2e5b
refactor: move tests
ChrisKujawa 9b2ab40
feat: apply patch to gw deployment
ChrisKujawa a49a44e
docs: add comment
ChrisKujawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022 Camunda Services GmbH | ||
// | ||
// 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 internal | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
v12 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (c K8Client) getGatewayDeployment() (*v12.Deployment, error) { | ||
listOptions := metav1.ListOptions{ | ||
LabelSelector: getSelfManagedGatewayLabels(), | ||
} | ||
deploymentList, err := c.Clientset.AppsV1().Deployments(c.GetCurrentNamespace()).List(context.TODO(), listOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if deploymentList == nil || len(deploymentList.Items) <= 0 { | ||
// lets check for SaaS setup | ||
listOptions.LabelSelector = getSaasGatewayLabels() | ||
deploymentList, err = c.Clientset.AppsV1().Deployments(c.GetCurrentNamespace()).List(context.TODO(), listOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// here it is currently hard to distingush between not existing and embedded gateway; | ||
// since we don't use embedded gateway in our current chaos setup I would not support it right now here | ||
if deploymentList == nil || len(deploymentList.Items) <= 0 { | ||
return nil, errors.New(fmt.Sprintf("Expected to find standalone gateway deployment in namespace %s, but none found!", c.GetCurrentNamespace())) | ||
} | ||
} | ||
|
||
return &deploymentList.Items[0], err | ||
} |
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,96 @@ | ||
// Copyright 2022 Camunda Services GmbH | ||
// | ||
// 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 internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func Test_ShouldReturnTrueForRunningGatewayDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
selector, err := metav1.ParseToLabelSelector(getSelfManagedGatewayLabels()) | ||
require.NoError(t, err) | ||
k8Client.CreateDeploymentWithLabelsAndName(t, selector, "gateway") | ||
|
||
// when | ||
running, err := k8Client.checkIfGatewaysAreRunning() | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Equal(t, true, running) | ||
} | ||
|
||
func Test_ShouldReturnTrueForRunningSaaSGatewayDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
selector, err := metav1.ParseToLabelSelector(getSaasGatewayLabels()) | ||
require.NoError(t, err) | ||
k8Client.CreateDeploymentWithLabelsAndName(t, selector, "gateway") | ||
|
||
// when | ||
running, err := k8Client.checkIfGatewaysAreRunning() | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Equal(t, true, running) | ||
} | ||
|
||
func Test_ShouldReturnErrorForNonExistingDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
|
||
// when | ||
running, err := k8Client.checkIfGatewaysAreRunning() | ||
|
||
// then | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Expected to find standalone gateway deployment") | ||
assert.Equal(t, false, running) | ||
} | ||
|
||
func Test_ShouldReturnGatewayDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
selector, err := metav1.ParseToLabelSelector(getSelfManagedGatewayLabels()) | ||
require.NoError(t, err) | ||
k8Client.CreateDeploymentWithLabelsAndName(t, selector, "gateway") | ||
|
||
// when | ||
deployment, err := k8Client.getGatewayDeployment() | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Equal(t, "gateway", deployment.Name) | ||
} | ||
|
||
func Test_ShouldReturnSaaSGatewayDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
selector, err := metav1.ParseToLabelSelector(getSaasGatewayLabels()) | ||
require.NoError(t, err) | ||
k8Client.CreateDeploymentWithLabelsAndName(t, selector, "gateway") | ||
|
||
// when | ||
deployment, err := k8Client.getGatewayDeployment() | ||
|
||
// then | ||
require.NoError(t, err) | ||
assert.Equal(t, "gateway", deployment.Name) | ||
} |
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,62 @@ | ||
// Copyright 2022 Camunda Services GmbH | ||
// | ||
// 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 internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func Test_ShouldApplyNetworkPatchOnStatefulSet(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
k8Client.CreateStatefulSetWithLabelsAndName(t, &metav1.LabelSelector{}, "zeebe") | ||
|
||
// when | ||
err := k8Client.ApplyNetworkPatch() | ||
|
||
// then | ||
require.NoError(t, err) | ||
|
||
statefulSet, err := k8Client.GetZeebeStatefulSet() | ||
require.NoError(t, err) | ||
|
||
require.NotNil(t, statefulSet) | ||
assert.Equal(t, v1.Capability("NET_ADMIN"), statefulSet.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities.Add[0], "Expected to add capability to statefulset") | ||
} | ||
|
||
func Test_ShouldApplyNetworkPatchOnDeployment(t *testing.T) { | ||
// given | ||
k8Client := CreateFakeClient() | ||
selector, err := metav1.ParseToLabelSelector(getSaasGatewayLabels()) | ||
require.NoError(t, err) | ||
k8Client.CreateDeploymentWithLabelsAndName(t, selector, "gateway") | ||
|
||
// when | ||
err = k8Client.ApplyNetworkPatchOnGateway() | ||
|
||
// then | ||
require.NoError(t, err) | ||
|
||
deployment, err := k8Client.getGatewayDeployment() | ||
require.NoError(t, err) | ||
|
||
require.NotNil(t, deployment) | ||
assert.Equal(t, v1.Capability("NET_ADMIN"), deployment.Spec.Template.Spec.Containers[0].SecurityContext.Capabilities.Add[0], "Expected to add capability to deployment") | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭
Nice that you got this working for SaaS too. I think the only thing missing would be to pause reconciliation. Same for all other functionality that modifies any of the resources managed by the
ZeebeCluster
CRD.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jep right now it is only this I think the other stuff is inside the container like disconnecting