generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add first version of x-kuberneets impl with unit tests #338
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29a2928
add first implementaion
dbadura 2dac9b1
bump images
dbadura f541e41
fix method name after rebase
dbadura ff29c07
use generate name to avoid conflicts and improve finding crd file
dbadura f9157f7
remove uncommented code in makefile
dbadura 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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
--- | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: MutatingWebhookConfiguration | ||
|
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
142 changes: 142 additions & 0 deletions
142
components/serverless/pkg/apis/serverless/v1alpha2/function_x_validation_test.go
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,142 @@ | ||
package v1alpha2_test | ||
|
||
import ( | ||
"context" | ||
"github.com/kyma-project/kyma/components/function-controller/internal/testenv" | ||
serverlessv1alpha2 "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
k8serrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"testing" | ||
) | ||
|
||
func Test_XKubernetesValidations(t *testing.T) { | ||
ctx := context.TODO() | ||
k8sClient, testEnv := testenv.Start(t) | ||
defer testenv.Stop(t, testEnv) | ||
|
||
testNs := corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "test"}, | ||
} | ||
err := k8sClient.Create(ctx, &testNs) | ||
require.NoError(t, err) | ||
|
||
testCases := map[string]struct { | ||
fn *serverlessv1alpha2.Function | ||
expectedErr bool | ||
expectedErrMsg string | ||
fieldPath string | ||
}{ | ||
"Resource and Profiles used together in function": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Function: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
Resources: &corev1.ResourceRequirements{}, | ||
}}, | ||
}, | ||
}, | ||
expectedErr: true, | ||
expectedErrMsg: "Use profile or resources", | ||
fieldPath: "spec.resourceConfiguration.function", | ||
}, | ||
"Profile set only for function": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Function: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
"Resource set only for function": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Function: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
"Resource and Profiles used together in buildJob": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Build: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
Resources: &corev1.ResourceRequirements{}, | ||
}}, | ||
}, | ||
}, | ||
expectedErr: true, | ||
expectedErrMsg: "Use profile or resources", | ||
fieldPath: "spec.resourceConfiguration.build", | ||
}, | ||
"Profile set only for buildJob": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Build: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
"Resource set only for buildJob": { | ||
fn: &serverlessv1alpha2.Function{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
GenerateName: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: serverlessv1alpha2.FunctionSpec{ | ||
ResourceConfiguration: &serverlessv1alpha2.ResourceConfiguration{Build: &serverlessv1alpha2.ResourceRequirements{ | ||
Profile: "Test", | ||
}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
//GIVEN | ||
|
||
//WHEN | ||
err := k8sClient.Create(ctx, tc.fn) | ||
//THEN | ||
if tc.expectedErr { | ||
require.Error(t, err) | ||
errStatus, ok := err.(*k8serrors.StatusError) | ||
require.True(t, ok) | ||
causes := errStatus.Status().Details.Causes | ||
require.Len(t, causes, 1) | ||
cause := causes[0] | ||
assert.Equal(t, metav1.CauseTypeFieldValueInvalid, cause.Type) | ||
assert.Equal(t, tc.fieldPath, cause.Field) | ||
assert.Contains(t, cause.Message, tc.expectedErrMsg) | ||
} else { | ||
require.NoError(t, err) | ||
require.NoError(t, k8sClient.Delete(ctx, tc.fn)) | ||
} | ||
}) | ||
} | ||
} |
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
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.
Where and why we use this directory?
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.
I was using it to keep local test files.