Skip to content

Commit

Permalink
Merge branch 'main' into update-ottl-adr
Browse files Browse the repository at this point in the history
  • Loading branch information
hisarbalik authored Dec 18, 2024
2 parents 3331f4d + 84d7fe2 commit 814c7a1
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 331 deletions.
6 changes: 5 additions & 1 deletion .github/template/prepare-test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ runs:
shell: bash
run: make --debug deploy-experimental

- name: Wait for manager readiness
- name: Wait for manager deployment rollout
shell: bash
run: kubectl -n kyma-system rollout status deployment telemetry-manager --timeout=90s

- name: Wait for manager readiness
shell: bash
run: kubectl -n kyma-system wait pods -l app.kubernetes.io/instance=telemetry,app.kubernetes.io/name=manager --for=condition=Ready=true --timeout=90s

- name: Print cluster info
shell: bash
run: |
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.61.0
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/pdata v1.21.0
go.opentelemetry.io/collector/pdata v1.22.0
go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.36.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -67,9 +67,9 @@ require (
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.26.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.68.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.opentelemetry.io/collector/pdata v1.21.0 h1:PG+UbiFMJ35X/WcAR7Rf/PWmWtRdW0aHlOidsR6c5MA=
go.opentelemetry.io/collector/pdata v1.21.0/go.mod h1:GKb1/zocKJMvxKbS+sl0W85lxhYBTFJ6h6I1tphVyDU=
go.opentelemetry.io/collector/pdata v1.22.0 h1:3yhjL46NLdTMoP8rkkcE9B0pzjf2973crn0KKhX5UrI=
go.opentelemetry.io/collector/pdata v1.22.0/go.mod h1:nLLf6uDg8Kn5g3WNZwGyu8+kf77SwOqQvMTb5AXEbEY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
Expand Down Expand Up @@ -162,12 +162,12 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 h1:YcyjlL1PRr2Q17/I0dPk2JmYS5CDXfcdb2Z3YRioEbw=
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:OCdP9MfskevB/rbYvHTsXTtKC+3bHWajPdoKgjcYkfo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 h1:2035KHhUv+EpyB+hWgJnaWKJOdX1E95w2S8Rr4uWKTs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc=
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:qpvKtACPCQhAdu3PyQgV4l3LMXZEtft7y8QcarRsp9I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 h1:pPJltXNxVzT4pK9yD8vR9X75DaWYYmLGMsEvBfFQZzQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
117 changes: 75 additions & 42 deletions internal/resources/otelcollector/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,65 @@ import (
)

func TestAgent_ApplyResources(t *testing.T) {
var objects []client.Object

scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(istiosecurityclientv1.AddToScheme(scheme))

client := fake.NewClientBuilder().WithInterceptorFuncs(interceptor.Funcs{
Create: func(_ context.Context, c client.WithWatch, obj client.Object, _ ...client.CreateOption) error {
objects = append(objects, obj)
// Nothing has to be created, just add created object to the list
return nil
},
}).Build()

image := "opentelemetry/collector:dummy"
namespace := "kyma-system"
priorityClassName := "normal"
sut := NewMetricAgentApplierDeleter(image, namespace, priorityClassName)

err := sut.ApplyResources(context.Background(), client, AgentApplyOptions{
AllowedPorts: []int32{5555, 6666},
CollectorConfigYAML: "dummy",
})
require.NoError(t, err)
tests := []struct {
name string
sut *AgentApplierDeleter
goldenFilePath string
saveGoldenFile bool
}{
{
name: "metric agent",
sut: NewMetricAgentApplierDeleter(image, namespace, priorityClassName),
goldenFilePath: "testdata/metric-agent.yaml",
},
}

for _, tt := range tests {
var objects []client.Object

scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(istiosecurityclientv1.AddToScheme(scheme))

fakeClient := fake.NewClientBuilder().WithInterceptorFuncs(interceptor.Funcs{
Create: func(_ context.Context, c client.WithWatch, obj client.Object, _ ...client.CreateOption) error {
objects = append(objects, obj)
// Nothing has to be created, just add created object to the list
return nil
},
}).Build()

t.Run(tt.name, func(t *testing.T) {
err := tt.sut.ApplyResources(context.Background(), fakeClient, AgentApplyOptions{
AllowedPorts: []int32{5555, 6666},
CollectorConfigYAML: "dummy",
})
require.NoError(t, err)

if tt.saveGoldenFile {
testutils.SaveAsYAML(t, scheme, objects, tt.goldenFilePath)
}

bytes, err := testutils.MarshalYAML(scheme, objects)
require.NoError(t, err)
bytes, err := testutils.MarshalYAML(scheme, objects)
require.NoError(t, err)

goldenFileBytes, err := os.ReadFile("testdata/metric-agent.yaml")
require.NoError(t, err)
goldenFileBytes, err := os.ReadFile(tt.goldenFilePath)
require.NoError(t, err)

require.Equal(t, string(goldenFileBytes), string(bytes))
require.Equal(t, string(goldenFileBytes), string(bytes))
})
}
}

func TestAgent_DeleteResources(t *testing.T) {
image := "opentelemetry/collector:dummy"
namespace := "kyma-system"
priorityClassName := "normal"

var created []client.Object

fakeClient := fake.NewClientBuilder().WithInterceptorFuncs(interceptor.Funcs{
Expand All @@ -63,23 +87,32 @@ func TestAgent_DeleteResources(t *testing.T) {
},
}).Build()

image := "opentelemetry/collector:dummy"
namespace := "kyma-system"
priorityClassName := "normal"
sut := NewMetricAgentApplierDeleter(image, namespace, priorityClassName)

err := sut.ApplyResources(context.Background(), fakeClient, AgentApplyOptions{
AllowedPorts: []int32{5555, 6666},
CollectorConfigYAML: "dummy",
})
require.NoError(t, err)

err = sut.DeleteResources(context.Background(), fakeClient)
require.NoError(t, err)
tests := []struct {
name string
sut *AgentApplierDeleter
}{
{
name: "metric agent",
sut: NewMetricAgentApplierDeleter(image, namespace, priorityClassName),
},
}

for i := range created {
// an update operation on a non-existent object should return a NotFound error
err = fakeClient.Get(context.Background(), client.ObjectKeyFromObject(created[i]), created[i])
require.True(t, apierrors.IsNotFound(err), "want not found, got %v: %#v", err, created[i])
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.sut.ApplyResources(context.Background(), fakeClient, AgentApplyOptions{
AllowedPorts: []int32{5555, 6666},
CollectorConfigYAML: "dummy",
})
require.NoError(t, err)

err = tt.sut.DeleteResources(context.Background(), fakeClient)
require.NoError(t, err)

for i := range created {
// an update operation on a non-existent object should return a NotFound error
err = fakeClient.Get(context.Background(), client.ObjectKeyFromObject(created[i]), created[i])
require.True(t, apierrors.IsNotFound(err), "want not found, got %v: %#v", err, created[i])
}
})
}
}
Loading

0 comments on commit 814c7a1

Please sign in to comment.