Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Oct 23, 2024
1 parent 875131f commit aa3840d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions apis/v1alpha1/tcxProgram_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
// +kubebuilder:printcolumn:name="Direction",type=string,JSONPath=`.spec.direction`,priority=1
// +kubebuilder:printcolumn:name="InterfaceSelector",type=string,JSONPath=`.spec.interfaceselector`,priority=1
// +kubebuilder:printcolumn:name="Position",type=string,JSONPath=`.spec.position`,priority=1
// +kubebuilder:printcolumn:name="Priority",type=string,JSONPath=`.spec.priority`,priority=1
type TcxProgram struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions bundle/manifests/bpfman.io_tcxprograms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
name: Position
priority: 1
type: string
- jsonPath: .spec.priority
name: Priority
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/bpfman.io_tcxprograms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
name: Position
priority: 1
type: string
- jsonPath: .spec.priority
name: Priority
priority: 1
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down
8 changes: 4 additions & 4 deletions controllers/bpfman-operator/tcx-program.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *TcxProgramReconciler) getFinalizer() string {
func (r *TcxProgramReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&bpfmaniov1alpha1.TcxProgram{}).
// Watch bpfPrograms which are owned by TcPrograms
// Watch bpfPrograms which are owned by TcxPrograms
Watches(
&bpfmaniov1alpha1.BpfProgram{},
&handler.EnqueueRequestForObject{},
Expand All @@ -65,7 +65,7 @@ func (r *TcxProgramReconciler) Reconcile(ctx context.Context, req ctrl.Request)

tcxProgram := &bpfmaniov1alpha1.TcxProgram{}
if err := r.Get(ctx, req.NamespacedName, tcxProgram); err != nil {
// list all TcProgram objects with
// list all TcxProgram objects with
if errors.IsNotFound(err) {
bpfProgram := &bpfmaniov1alpha1.BpfProgram{}
if err := r.Get(ctx, req.NamespacedName, bpfProgram); err != nil {
Expand All @@ -87,7 +87,7 @@ func (r *TcxProgramReconciler) Reconcile(ctx context.Context, req ctrl.Request)
if errors.IsNotFound(err) {
r.Logger.Info("tcxProgram from ownerRef not found stale reconcile exiting", "Name", req.NamespacedName)
} else {
r.Logger.Error(err, "failed getting TcProgram Object from ownerRef", "Name", req.NamespacedName)
r.Logger.Error(err, "failed getting TcxProgram Object from ownerRef", "Name", req.NamespacedName)
}
return ctrl.Result{}, nil

Check warning on line 92 in controllers/bpfman-operator/tcx-program.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-operator/tcx-program.go#L86-L92

Added lines #L86 - L92 were not covered by tests
}
Expand All @@ -102,7 +102,7 @@ func (r *TcxProgramReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

func (r *TcxProgramReconciler) updateStatus(ctx context.Context, name string, cond bpfmaniov1alpha1.ProgramConditionType, message string) (ctrl.Result, error) {
// Sometimes we end up with a stale TcProgram due to races, do this
// Sometimes we end up with a stale TcxProgram due to races, do this
// get to ensure we're up to date before attempting a finalizer removal.
prog := &bpfmaniov1alpha1.TcxProgram{}
if err := r.Get(ctx, types.NamespacedName{Namespace: corev1.NamespaceAll, Name: name}, prog); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func doAppTcCheck(t *testing.T, output *bytes.Buffer) bool {
return false
}

func doTcxCheck(t *testing.T, output *bytes.Buffer) bool {
if strings.Contains(output.String(), "packets received") && strings.Contains(output.String(), "bytes received") {
t.Log("TCX BPF program is functioning")
return true
}
return false
}

func doAppTcxCheck(t *testing.T, output *bytes.Buffer) bool {
str := `TCX: received (\d+) packets`
if ok, count := doProbeCommonCheck(t, output, str); ok {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/tcx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func TestTcxGoCounter(t *testing.T) {

pods, err := env.Cluster().Client().CoreV1().Pods(tcxGoCounterUserspaceNs).List(ctx, metav1.ListOptions{LabelSelector: "name=go-tcx-counter"})
require.NoError(t, err)
gotcCounterPod := pods.Items[0]
gotcxCounterPod := pods.Items[0]

req := env.Cluster().Client().CoreV1().Pods(tcxGoCounterUserspaceNs).GetLogs(gotcCounterPod.Name, &corev1.PodLogOptions{})
req := env.Cluster().Client().CoreV1().Pods(tcxGoCounterUserspaceNs).GetLogs(gotcxCounterPod.Name, &corev1.PodLogOptions{})

require.Eventually(t, func() bool {
logs, err := req.Stream(ctx)
Expand All @@ -54,6 +54,6 @@ func TestTcxGoCounter(t *testing.T) {
require.NoError(t, err)
t.Logf("counter pod log %s", output.String())

return doTcCheck(t, output)
return doTcxCheck(t, output)
}, 30*time.Second, time.Second)
}

0 comments on commit aa3840d

Please sign in to comment.