-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: add resources e2e #329
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ package envfuncsext | |
import ( | ||
"context" | ||
stderrors "errors" | ||
"reflect" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/e2e-framework/pkg/envconf" | ||
|
||
|
@@ -46,7 +49,7 @@ func DefaultNebulaClusterReadyFunc(ctx context.Context, cfg *envconf.Config, nc | |
return true, nil | ||
} | ||
|
||
func NebulaClusterReadyFuncForFields(ignoreValidationErrors bool, rulesMapping map[string]e2evalidator.Rule) NebulaClusterReadyFunc { | ||
func NebulaClusterReadyFuncForFields(ignoreValidationErrors bool, rulesMapping map[string]e2evalidator.Ruler) NebulaClusterReadyFunc { | ||
return func(_ context.Context, _ *envconf.Config, nc *appsv1alpha1.NebulaCluster) (isReady bool, err error) { | ||
if errMessages := e2evalidator.StructWithRules(nc, rulesMapping); len(errMessages) > 0 { | ||
if ignoreValidationErrors { | ||
|
@@ -61,7 +64,7 @@ func NebulaClusterReadyFuncForFields(ignoreValidationErrors bool, rulesMapping m | |
} | ||
} | ||
|
||
func defaultNebulaClusterReadyFuncForStatus(_ context.Context, _ *envconf.Config, nc *appsv1alpha1.NebulaCluster) (bool, error) { | ||
func defaultNebulaClusterReadyFuncForStatus(ctx context.Context, cfg *envconf.Config, nc *appsv1alpha1.NebulaCluster) (bool, error) { | ||
isReady := nc.IsReady() | ||
if isReady { | ||
// TODO: Add more checks | ||
|
@@ -110,6 +113,24 @@ func defaultNebulaClusterReadyFuncForStatus(_ context.Context, _ *envconf.Config | |
) | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This func is used to cmp nc status, maybe put those in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
{ // Metad Resource checks | ||
if !isComponentResourceExpected(ctx, cfg, nc.MetadComponent()) { | ||
isReady = false | ||
} | ||
} | ||
|
||
{ // Storaged Resource checks | ||
if !isComponentResourceExpected(ctx, cfg, nc.StoragedComponent()) { | ||
isReady = false | ||
} | ||
} | ||
|
||
{ // Graphd Resource checks | ||
if !isComponentResourceExpected(ctx, cfg, nc.GraphdComponent()) { | ||
isReady = false | ||
} | ||
} | ||
} | ||
|
||
return isReady, nil | ||
|
@@ -152,7 +173,7 @@ func isComponentStatusExpected( | |
) bool { | ||
if errMessages := e2evalidator.StructWithRules( | ||
componentStatus, | ||
map[string]e2evalidator.Rule{ | ||
map[string]e2evalidator.Ruler{ | ||
"Version": e2evalidator.Eq(componentSpec.Version), | ||
"Phase": e2evalidator.Eq(appsv1alpha1.RunningPhase), | ||
"Workload.ReadyReplicas": e2evalidator.Eq(*componentSpec.Replicas), | ||
|
@@ -173,3 +194,41 @@ func isComponentStatusExpected( | |
|
||
return true | ||
} | ||
|
||
func isComponentResourceExpected(ctx context.Context, cfg *envconf.Config, component appsv1alpha1.NebulaClusterComponent) bool { | ||
sts := &appsv1.StatefulSet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: component.GetName(), | ||
Namespace: component.GetNamespace(), | ||
}, | ||
} | ||
|
||
if err := cfg.Client().Resources().Get(ctx, sts.Name, sts.Namespace, sts); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have already obtained it, why not check more fields, such as version, replicas , etc. |
||
klog.InfoS("Check Component Resource but statefulset not found", | ||
"namespace", sts.Namespace, | ||
"name", sts.Name, | ||
) | ||
return false | ||
} | ||
|
||
for _, c := range sts.Spec.Template.Spec.Containers { | ||
if c.Name != component.ComponentType().String() { | ||
continue | ||
} | ||
resource := component.ComponentSpec().Resources() | ||
if reflect.DeepEqual(c.Resources.DeepCopy(), resource) { | ||
return true | ||
} else { | ||
klog.InfoS("Check Component Resource but not expected", | ||
"namespace", sts.Namespace, | ||
"name", sts.Name, | ||
"requests", c.Resources.Requests, | ||
"requestsExpected", resource.Requests, | ||
"limits", c.Resources.Limits, | ||
"limitsExpected", resource.Limits, | ||
) | ||
} | ||
} | ||
|
||
return false | ||
} |
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.
Perhaps the definition could be more abstract rather than specific to a certain type.
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.
ok