Skip to content

Commit

Permalink
Merge branch 'main' into cortex-config-monitoring-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed Aug 23, 2023
2 parents 6c78a25 + a1e85dc commit 8a51021
Show file tree
Hide file tree
Showing 128 changed files with 1,390 additions and 29,784 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
-e _EXPERIMENTAL_DAGGER_CACHESERVICE_TOKEN=$_EXPERIMENTAL_DAGGER_CACHESERVICE_TOKEN \
-e _EXPERIMENTAL_DAGGER_CACHESERVICE_URL=https://api.dagger.cloud/magicache \
-v dagger-engine:/var/lib/dagger \
registry.dagger.io/engine:v0.8.2
registry.dagger.io/engine:v0.8.3
volumes: &volumes
- name: docker-sock
path: /var/run/docker.sock
Expand Down Expand Up @@ -65,7 +65,7 @@ steps:
environment: *environment
volumes: *volumes
commands:
- go run ./dagger -c dagger/ci/defaults,dagger/ci/push,dagger/ci/push-charts,dagger/ci/tag-latest --lint=false --test=false
- go run ./dagger -c dagger/ci/defaults,dagger/ci/push,dagger/ci/push-charts,dagger/ci/tag-latest,dagger/ci/tag-release --lint=false --test=false
when:
event:
- tag
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load('ext://namespace', 'namespace_create')

set_team('52cc75cc-c4ed-462f-8ea7-a543d398a381')

version = '0.11.0'
version = '0.11.1'
config.define_string_list('allowedContexts')
config.define_string_list('opniChartValues')
config.define_string('defaultRegistry')
Expand Down
14 changes: 14 additions & 0 deletions apis/monitoring/v1beta1/prometheus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
promoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
promoperatorv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
"github.com/rancher/wrangler/pkg/crd"
"github.com/rancher/wrangler/pkg/schemas/openapi"
)
Expand Down Expand Up @@ -44,3 +45,16 @@ func PrometheusCRD() (*crd.CRD, error) {
Schema: schema,
}, nil
}

func PrometheusAgentCRD() (*crd.CRD, error) {
schema, err := openapi.ToOpenAPIFromStruct(promoperatorv1alpha1.PrometheusAgent{})
if err != nil {
return nil, err
}
return &crd.CRD{
GVK: promoperatorv1alpha1.SchemeGroupVersion.WithKind("PrometheusAgent"),
PluralName: "prometheusagents",
Status: true,
Schema: schema,
}, nil
}
6 changes: 5 additions & 1 deletion apis/scheme_prometheus.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package apis

import monitoringcoreosv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
import (
monitoringcoreosv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringcoreosv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
)

func init() {
addSchemeBuilders(monitoringcoreosv1.AddToScheme)
addSchemeBuilders(monitoringcoreosv1alpha1.AddToScheme)
}
132 changes: 124 additions & 8 deletions controllers/core_collector_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

opnimonitoringv1beta1 "github.com/rancher/opni/apis/monitoring/v1beta1"
"github.com/rancher/opni/pkg/otel"
"github.com/samber/lo"
"sigs.k8s.io/controller-runtime/pkg/client"

. "github.com/kralicky/kmatch"
Expand All @@ -21,14 +22,12 @@ import (
)

var _ = Describe("Core Collector Controller", Ordered, Label("controller", "slow"), func() {
var (
ns string
loggingConfig *opniloggingv1beta1.CollectorConfig
monitoringConfig *opnimonitoringv1beta1.CollectorConfig
metricsCollectorObj *opnicorev1beta1.Collector
loggingCollectorObj *opnicorev1beta1.Collector
)
When("creating a collector resource for monitoring", func() {
When("creating a collector resource for monitoring with host metrics", func() {
var (
ns string
monitoringConfig *opnimonitoringv1beta1.CollectorConfig
metricsCollectorObj *opnicorev1beta1.Collector
)
It("should succeed in creating the objects", func() {
ns = makeTestNamespace()
monitoringConfig = &opnimonitoringv1beta1.CollectorConfig{
Expand All @@ -40,6 +39,9 @@ var _ = Describe("Core Collector Controller", Ordered, Label("controller", "slow
PrometheusDiscovery: opnimonitoringv1beta1.PrometheusDiscovery{
NamespaceSelector: []string{ns},
},
OtelSpec: otel.OTELSpec{
HostMetrics: lo.ToPtr(true),
},
},
}
metricsCollectorObj = &opnicorev1beta1.Collector{
Expand Down Expand Up @@ -154,7 +156,121 @@ var _ = Describe("Core Collector Controller", Ordered, Label("controller", "slow
})
})

When("creating a collector resource for monitoring without host metrics", func() {
var (
ns string
monitoringConfig *opnimonitoringv1beta1.CollectorConfig
metricsCollectorObj *opnicorev1beta1.Collector
)
It("should succeed in creating the objects", func() {
ns = makeTestNamespace()
monitoringConfig = &opnimonitoringv1beta1.CollectorConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "test-monitoring",
},
Spec: opnimonitoringv1beta1.CollectorConfigSpec{
RemoteWriteEndpoint: "http://test-endpoint",
PrometheusDiscovery: opnimonitoringv1beta1.PrometheusDiscovery{
NamespaceSelector: []string{ns},
},
OtelSpec: otel.OTELSpec{
HostMetrics: lo.ToPtr(false),
},
},
}
metricsCollectorObj = &opnicorev1beta1.Collector{
ObjectMeta: metav1.ObjectMeta{
Name: "test-monitoring2",
},
Spec: opnicorev1beta1.CollectorSpec{
SystemNamespace: ns,
AgentEndpoint: "http://test-endpoint",
MetricsConfig: &corev1.LocalObjectReference{
Name: "test-monitoring",
},
},
}

By("creating the otel collector configs for metrics")
Expect(k8sClient.Create(context.Background(), monitoringConfig)).To(Succeed())
Expect(k8sClient.Create(context.Background(), metricsCollectorObj)).To(Succeed())

By("creating physical objects for discovery")
for _, obj := range promDiscoveryObejcts(ns) {
Expect(k8sClient.Create(context.Background(), obj)).To(Succeed())
}
})

It("should create the monitoring infra", func() {
By("checking the the aggregator config map embeds scrape configs and selectors")
By("checking aggregator configmap")
Eventually(Object(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-aggregator-config", metricsCollectorObj.Name),
Namespace: ns,
},
})).Should(ExistAnd(
HaveData("aggregator.yaml", nil),
HaveOwner(metricsCollectorObj),
))
By("checking daemonset does not exist")
Consistently(Object(&appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-collector-agent", metricsCollectorObj.Name),
Namespace: ns,
},
})).ShouldNot(Exist())
By("checking aggregator deployment")
Eventually(Object(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-collector-aggregator", metricsCollectorObj.Name),
Namespace: ns,
},
})).Should(ExistAnd(
HaveMatchingContainer(And(
HaveName("otel-collector"),
HaveVolumeMounts("collector-config"),
)),
HaveMatchingVolume(And(
HaveVolumeSource("ConfigMap"),
HaveName("collector-config"),
)),
HaveOwner(metricsCollectorObj),
))
By("checking the metrics tls assets secrets exists")
Eventually(Object(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "opni-otel-tls-assets",
Namespace: ns,
},
})).Should(ExistAnd(
HaveOwner(metricsCollectorObj),
))
})
// FIXME: this requires the mock k8s instance to set object endpoints or pod ips
XIt("should mount required tls assets for service monitors based on prometheus crds", func() {
Eventually(Object(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "opni-otel-tls-assets",
Namespace: ns,
},
})).Should(ExistAnd(
HaveOwner(metricsCollectorObj),
HaveData(
"ca.crt", "test-ca",
"tls.crt", "test-cert",
"tls.key", "test-key",
),
))
})
})

When("creating a collector resource for logging", func() {
var (
ns string
loggingConfig *opniloggingv1beta1.CollectorConfig
loggingCollectorObj *opnicorev1beta1.Collector
)
It("should succeed in creating the objects", func() {
ns = makeTestNamespace()
loggingConfig = &opniloggingv1beta1.CollectorConfig{
Expand Down
7 changes: 6 additions & 1 deletion dagger/ci/defaults.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
lint = true
test = true

[releaser]
repo = "github.com/rancher/opni"
os = ["darwin", "linux"]
arch = ["amd64"]

[charts.git]
repo = "github.com/rancher/opni"
branch = "charts-repo"
Expand All @@ -21,7 +26,7 @@ test = true
[images.opensearch.build]
dashboards-version = "2.8.0"
opensearch-version = "2.8.0"
plugin-version = "0.11.0"
plugin-version = "0.11.1"

[images.opensearch.dashboards]
repo = "docker.io/rancher/opensearch-dashboards"
Expand Down
2 changes: 2 additions & 0 deletions dagger/ci/tag-release.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[releaser]
push = true
13 changes: 13 additions & 0 deletions dagger/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type BuilderConfig struct {
Lint bool `koanf:"lint"`
Test bool `koanf:"test"`
Coverage CoverageConfig `koanf:"coverage"`
Releaser ReleaseTarget `koanf:"releaser"`
}

type ImagesConfig struct {
Expand Down Expand Up @@ -68,6 +69,15 @@ type ChartTarget struct {
Auth AuthConfig `koanf:"auth" validate:"required_if=Push true"`
}

type ReleaseTarget struct {
Push bool `koanf:"push"`
OS []string `koanf:"os"`
Arch []string `koanf:"arch"`
Repo string `koanf:"repo" validate:"required_if=Push true"`
Tag string `koanf:"tag" validate:"required_if=Push true"`
Auth AuthConfig `koanf:"auth" validate:"required_if=Push true"`
}

type OpensearchConfig struct {
Opensearch ImageTarget `koanf:"opensearch"`
Dashboards ImageTarget `koanf:"dashboards"`
Expand Down Expand Up @@ -207,6 +217,9 @@ func mergeStrict(src, dest map[string]any) error {
reflect.TypeOf(val) == reflect.TypeOf(([]any)(nil)) &&
reflect.ValueOf(dest[key]).Len() == 0 {
dest[key] = reflect.MakeSlice(reflect.TypeOf(dest[key]), 0, 0).Interface()
for _, v := range val.([]any) {
dest[key] = reflect.Append(reflect.ValueOf(dest[key]), reflect.ValueOf(v)).Interface()
}
continue
}
return fmt.Errorf("incorrect types at key %v, type %T != %T", key, dest[key], val)
Expand Down
1 change: 1 addition & 0 deletions dagger/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func SpecialCaseEnvVars(client *dagger.Client) []SpecialCaseEnv {
EnvVar: "GH_TOKEN",
Keys: []string{
"charts.git.auth.secret",
"releaser.auth.secret",
},
Converter: secret,
},
Expand Down
5 changes: 3 additions & 2 deletions dagger/config/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"path/filepath"
"strings"

"slices"

"github.com/AlecAivazis/survey/v2"
"github.com/bmatcuk/doublestar/v4"
"github.com/knadh/koanf/providers/structs"
"github.com/knadh/koanf/v2"
"golang.org/x/exp/slices"
)

type answerWriter struct {
Expand Down Expand Up @@ -60,7 +61,7 @@ func RunSetup() {
Build: OpensearchBuildConfig{
DashboardsVersion: "2.8.0",
OpensearchVersion: "2.8.0",
PluginVersion: "0.11.0",
PluginVersion: "0.11.1",
},
},
},
Expand Down
5 changes: 1 addition & 4 deletions dagger/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/rancher/opni/dagger
go 1.21

require (
dagger.io/dagger v0.8.2
dagger.io/dagger v0.8.3
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/bmatcuk/doublestar/v4 v4.6.0
github.com/go-playground/validator/v10 v10.14.1
Expand All @@ -19,7 +19,6 @@ require (
github.com/mitchellh/copystructure v1.2.0
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
golang.org/x/sync v0.3.0
)

Expand Down Expand Up @@ -51,12 +50,10 @@ require (
github.com/stretchr/testify v1.8.4 // indirect
github.com/vektah/gqlparser/v2 v2.5.8 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 8a51021

Please sign in to comment.