Skip to content
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

Upstream refresh kartikeya #303

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
93306d4
copy config.go from main branch
kpharasi Jul 23, 2024
3a26a13
copy config_test.go from main branch
kpharasi Jul 23, 2024
9918428
copy metrics.go from main branch
kpharasi Jul 23, 2024
39abb3c
copy metrics_test.go from main branch
kpharasi Jul 23, 2024
1988af0
copy rolloutcommon.go from main branch
kpharasi Jul 23, 2024
de0e1dd
copy rolloutcommon_test.go from main branch
kpharasi Jul 23, 2024
eec84b2
copy types.go from main branch
kpharasi Jul 23, 2024
23f7b3a
copy types_test.go from main branch
kpharasi Jul 23, 2024
10fc941
copy destinationrule.go from main branch
kpharasi Jul 23, 2024
fc163ce
copy destinationrule_test.go from main branch
kpharasi Jul 23, 2024
1c0d228
copy serviceentry.go from main branch
kpharasi Jul 23, 2024
2b74525
copy serviceentry_test.go from main branch
kpharasi Jul 23, 2024
8a13bcc
copy sidecar.go from main branch
kpharasi Jul 23, 2024
2a79a28
copy sidecar_test.go from main branch
kpharasi Jul 23, 2024
efd7bec
copy virtualservice.go from main branch
kpharasi Jul 23, 2024
a39e2e9
copy virtualservice_test.go from main branch
kpharasi Jul 23, 2024
7bcebac
copy defaultresolver_test.go from main branch
kpharasi Jul 23, 2024
e970336
copy secretcontroller.go from main branch
kpharasi Jul 23, 2024
5544328
copy secretcontroller_test.go from main branch
kpharasi Jul 23, 2024
5a0c278
copy migration.go from main branch
kpharasi Jul 23, 2024
38921ae
copy migration_test.go from main branch
kpharasi Jul 23, 2024
b2b1449
copy util.go from main branch
kpharasi Jul 23, 2024
5ae6c66
copy util_test.go from main branch
kpharasi Jul 23, 2024
4acc5e4
copy clusterIdentity.go from main branch
kpharasi Jul 23, 2024
8aaa1d2
copy clusterShard.go from main branch
kpharasi Jul 23, 2024
d9c70fa
copy clusterShard_test.go from main branch
kpharasi Jul 23, 2024
578e39a
copy clusterdentity_test.go from main branch
kpharasi Jul 23, 2024
18c2af7
copy configSyncer.go from main branch
kpharasi Jul 23, 2024
c54bac5
copy ClusterShardStore.go from main branch
kpharasi Jul 23, 2024
4c56908
copy registry.go from main branch
kpharasi Jul 23, 2024
7bc5b9c
copy registry_test.go from main branch
kpharasi Jul 23, 2024
ca1c853
copy serviceentry.go from main branch
kpharasi Jul 23, 2024
856e045
copy serviceentry_test.go from main branch
kpharasi Jul 23, 2024
67f18e4
copy mock.go from main branch
kpharasi Jul 23, 2024
2212502
copy types.go from main branch
kpharasi Jul 23, 2024
accfdb0
copy constants.go from main branch
kpharasi Jul 23, 2024
7148c08
copy util.go from main branch
kpharasi Jul 23, 2024
48c16f4
copy util_test.go from main branch
kpharasi Jul 23, 2024
4a7cc15
copy variables.go from main branch
kpharasi Jul 23, 2024
34b9e96
copy compatibility.md from main branch
kpharasi Jul 23, 2024
2db2452
copy examples.md from main branch
kpharasi Jul 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
396 changes: 356 additions & 40 deletions admiral/pkg/controller/common/config.go

Large diffs are not rendered by default.

179 changes: 139 additions & 40 deletions admiral/pkg/controller/common/config_test.go
Original file line number Diff line number Diff line change
@@ -1,78 +1,96 @@
package common

import (
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"

log "github.com/sirupsen/logrus"
)

func TestConfigManagement(t *testing.T) {
var configTestSingleton sync.Once

func setupForConfigTests() {
var initHappened bool
configTestSingleton.Do(func() {
p := AdmiralParams{
KubeconfigPath: "testdata/fake.config",
LabelSet: &LabelSet{
WorkloadIdentityKey: "identity",
AdmiralCRDIdentityLabel: "identity",
IdentityPartitionKey: "admiral.io/identityPartition",
},
EnableSAN: true,
SANPrefix: "prefix",
HostnameSuffix: "mesh",
SyncNamespace: "admiral-sync",
SecretFilterTags: "admiral/sync",
CacheReconcileDuration: time.Minute,
ClusterRegistriesNamespace: "default",
DependenciesNamespace: "default",
Profile: "default",
WorkloadSidecarName: "default",
WorkloadSidecarUpdate: "disabled",
MetricsEnabled: true,
DeprecatedEnvoyFilterVersion: "1.10,1.17",
EnvoyFilterVersion: "1.10,1.13,1.17",
CartographerFeatures: map[string]string{"throttle_filter_gen": "disabled"},
DisableIPGeneration: false,
EnableSWAwareNSCaches: true,
ExportToIdentityList: []string{"*"},
ExportToMaxNamespaces: 35,
}
ResetSync()
initHappened = true
InitializeConfig(p)
})
if !initHappened {
log.Warn("InitializeConfig was NOT called from setupForConfigTests")
} else {
log.Info("InitializeConfig was called setupForConfigTests")
}
}

//Initial state comes from the init method in configInitializer.go
//p := AdmiralParams{
// KubeconfigPath: "testdata/fake.config",
// LabelSet: &LabelSet{},
// EnableSAN: true,
// SANPrefix: "prefix",
// HostnameSuffix: "mesh",
// SyncNamespace: "ns",
//}
//
//p.LabelSet.WorkloadIdentityKey="identity"

//trying to initialize again. If the singleton pattern works, none of these will have changed
p := AdmiralParams{
KubeconfigPath: "DIFFERENT",
LabelSet: &LabelSet{},
EnableSAN: false,
SANPrefix: "BAD_PREFIX",
HostnameSuffix: "NOT_MESH",
SyncNamespace: "NOT_A_NAMESPACE",
CacheRefreshDuration: time.Hour,
ClusterRegistriesNamespace: "NOT_DEFAULT",
DependenciesNamespace: "NOT_DEFAULT",
SecretResolver: "INSECURE_RESOLVER",
}

p.LabelSet.WorkloadIdentityKey = "BAD_LABEL"
p.LabelSet.GlobalTrafficDeploymentLabel = "ANOTHER_BAD_LABEL"

InitializeConfig(p)
func TestConfigManagement(t *testing.T) {
setupForConfigTests()

if GetWorkloadIdentifier() != "identity" {
t.Errorf("Workload identifier mismatch, expected identity, got %v", GetWorkloadIdentifier())
}
if GetKubeconfigPath() != "testdata/fake.config" {
t.Errorf("Kubeconfig path mismatch, expected testdata/fake.config, got %v", GetKubeconfigPath())
}
if GetSecretFilterTags() != "admiral/sync" {
t.Errorf("Filter tags mismatch, expected admiral/sync, got %v", GetSecretFilterTags())
}
if GetSANPrefix() != "prefix" {
t.Errorf("San prefix mismatch, expected prefix, got %v", GetSANPrefix())
}
if GetHostnameSuffix() != "mesh" {
t.Errorf("Hostname suffix mismatch, expected mesh, got %v", GetHostnameSuffix())
}
if GetSyncNamespace() != "ns" {
if GetSyncNamespace() != "admiral-sync" {
t.Errorf("Sync namespace mismatch, expected ns, got %v", GetSyncNamespace())
}
if GetEnableSAN() != true {
t.Errorf("Enable SAN mismatch, expected true, got %v", GetEnableSAN())
}
if GetCacheRefreshDuration() != time.Minute {
t.Errorf("Cachee refresh duration mismatch, expected %v, got %v", time.Minute, GetCacheRefreshDuration())
t.Errorf("Cache refresh duration mismatch, expected %v, got %v", time.Minute, GetCacheRefreshDuration())
}
if GetClusterRegistriesNamespace() != "default" {
t.Errorf("Cluster registry namespace mismatch, expected default, got %v", GetClusterRegistriesNamespace())
}
if GetDependenciesNamespace() != "default" {
t.Errorf("Dependency namespace mismatch, expected default, got %v", GetDependenciesNamespace())
}
if GetSecretResolver() != "" {
t.Errorf("Secret resolver mismatch, expected empty string, got %v", GetSecretResolver())
if GetAdmiralProfile() != "default" {
t.Errorf("Secret resolver mismatch, expected empty string, got %v", GetAdmiralProfile())
}
if GetGlobalTrafficDeploymentLabel() != "identity" {
t.Fatalf("GTP Deployment label mismatch. Expected identity, got %v", GetGlobalTrafficDeploymentLabel())
}
if GetGlobalTrafficDeploymentLabel() != "identity" {
t.Fatalf("GTP Deployment label mismatch. Expected identity, got %v", GetGlobalTrafficDeploymentLabel())
if GetAdmiralCRDIdentityLabel() != "identity" {
t.Fatalf("Admiral CRD Identity label mismatch. Expected identity, got %v", GetAdmiralCRDIdentityLabel())
}
if GetWorkloadSidecarName() != "default" {
t.Fatalf("Workload Sidecar Name mismatch. Expected default, got %v", GetWorkloadSidecarName())
Expand All @@ -91,4 +109,85 @@ func TestConfigManagement(t *testing.T) {
t.Errorf("Enable Prometheus mismatch, expected false, got %v", GetMetricsEnabled())
}

if IsPersonaTrafficConfig() != false {
t.Errorf("Enable Traffic Persona mismatch, expected false, got %v", IsPersonaTrafficConfig())
}

if IsDefaultPersona() != true {
t.Errorf("Enable Default Persona mismatch, expected false, got %v", IsDefaultPersona())
}

if len(GetDeprecatedEnvoyFilterVersion()) != 2 {
t.Errorf("Get deprecated envoy filter version by splitting with ',', expected 2, got %v", len(GetDeprecatedEnvoyFilterVersion()))
}

if len(GetEnvoyFilterVersion()) != 3 {
t.Errorf("Get envoy filter version by splitting with ',', expected 3, got %v", len(GetEnvoyFilterVersion()))
}

if IsCartographerFeatureDisabled("router_filter_gen") {
t.Errorf("If the feature is not present in the list should be assumed as enabled/true ',', expected false, got %v", IsCartographerFeatureDisabled("router_filter_gen"))
}

if !IsCartographerFeatureDisabled("throttle_filter_gen") {
t.Errorf("If the feature is present in the list with valure disabled. ',', expected true, got %v", IsCartographerFeatureDisabled("throttle_filter_gen"))
}

if DisableIPGeneration() {
t.Errorf("Disable IP Address Generation mismatch, expected false, got %v", DisableIPGeneration())
}

if GetPartitionIdentifier() != "admiral.io/identityPartition" {
t.Errorf("Get identity partition mismatch, expected admiral.io/identityPartition, got %v", GetPartitionIdentifier())
}

if !EnableSWAwareNSCaches() {
t.Errorf("enable SW aware namespace caches mismatch, expected true, got %v", EnableSWAwareNSCaches())
}

if !EnableExportTo("fakeIdentity") {
t.Errorf("enable exportTo mismatch, expected true, got %v", EnableExportTo("fakeIdentity"))
}

if GetExportToMaxNamespaces() != 35 {
t.Errorf("exportTo max namespaces mismatch, expected 35, got %v", GetExportToMaxNamespaces())
}
}

func TestGetCRDIdentityLabelWithCRDIdentity(t *testing.T) {

admiralParams := GetAdmiralParams()
backOldIdentity := admiralParams.LabelSet.AdmiralCRDIdentityLabel
admiralParams.LabelSet.AdmiralCRDIdentityLabel = "identityOld"

assert.Equalf(t, "identityOld", GetAdmiralCRDIdentityLabel(), "GetCRDIdentityLabel()")

admiralParams.LabelSet.AdmiralCRDIdentityLabel = backOldIdentity
}

//func TestGetCRDIdentityLabelWithLabel(t *testing.T) {
//
// admiralParams := GetAdmiralParams()
// backOldIdentity := admiralParams.LabelSet.AdmiralCRDIdentityLabel
// backOldGTPLabel := admiralParams.LabelSet.GlobalTrafficDeploymentLabel
// admiralParams.LabelSet.GlobalTrafficDeploymentLabel = "identityGTP"
//
// assert.Equalf(t, "identityGTP", GetAdmiralCRDIdentityLabel(), "GetAdmiralCRDIdentityLabel()")
//
// admiralParams.LabelSet.CRDIdentityLabel = backOldIdentity
// admiralParams.LabelSet.GlobalTrafficDeploymentLabel = backOldGTPLabel
//}

//func TestGetCRDIdentityLabelWithEmptyLabel(t *testing.T) {
//
// admiralParams := GetAdmiralParams()
// backOldIdentity := admiralParams.LabelSet.CRDIdentityLabel
// backOldGTPLabel := admiralParams.LabelSet.GlobalTrafficDeploymentLabel
// admiralParams.LabelSet.GlobalTrafficDeploymentLabel = ""
//
// assert.Equalf(t, "", GetCRDIdentityLabel(), "GetCRDIdentityLabel()")
//
// admiralParams.LabelSet.GlobalTrafficDeploymentLabel = ""
// admiralParams.LabelSet.CRDIdentityLabel = backOldIdentity
// admiralParams.LabelSet.GlobalTrafficDeploymentLabel = backOldGTPLabel
//}
90 changes: 11 additions & 79 deletions admiral/pkg/controller/common/metrics.go
Original file line number Diff line number Diff line change
@@ -1,100 +1,32 @@
package common

import (
"github.com/prometheus/client_golang/prometheus"
"sync"
)
import "github.com/prometheus/client_golang/prometheus"

const (
ClustersMonitoredMetricName = "clusters_monitored"
EventsProcessedTotalMetricName = "events_processed_total"

AddEventLabelValue = "add"
UpdateEventLabelValue = "update"
DeleteEventLabelValue = "delete"
)

var (
metricsOnce sync.Once
RemoteClustersMetric Gauge
EventsProcessed Counter
)
const ClustersMonitoredMetricName = "clusters_monitored"
const DependencyProxyServiceCacheSizeMetricName = "dependency_proxy_service_cache_size"

type Gauge interface {
With(labelValues ...string) Gauge
Set(value float64)
}

type Counter interface {
With(labelValues ...string) Counter
Inc()
}

/*
InitializeMetrics depends on AdmiralParams for metrics enablement.
*/
func InitializeMetrics() {
metricsOnce.Do(func() {
RemoteClustersMetric = NewGaugeFrom(ClustersMonitoredMetricName, "Gauge for the clusters monitored by Admiral", []string{})
EventsProcessed = NewCounterFrom(EventsProcessedTotalMetricName, "Counter for the events processed by Admiral", []string{"cluster", "object_type", "event_type"})
})
}

func NewGaugeFrom(name string, help string, labelNames []string) Gauge {
func NewGaugeFrom(name string, help string) Gauge {
if !GetMetricsEnabled() {
return &NoopGauge{}
return &Noop{}
}
opts := prometheus.GaugeOpts{Name: name, Help: help}
g := prometheus.NewGaugeVec(opts, labelNames)
g := prometheus.NewGauge(opts)
prometheus.MustRegister(g)
return &PromGauge{g, labelNames}
return &PromGauge{g}
}

func NewCounterFrom(name string, help string, labelNames []string) Counter {
if !GetMetricsEnabled() {
return &NoopCounter{}
}
opts := prometheus.CounterOpts{Name: name, Help: help}
c := prometheus.NewCounterVec(opts, labelNames)
prometheus.MustRegister(c)
return &PromCounter{c, labelNames}
}

type NoopGauge struct{}
type NoopCounter struct{}
type Noop struct{}

type PromGauge struct {
g *prometheus.GaugeVec
lvs []string
}

type PromCounter struct {
c *prometheus.CounterVec
lvs []string
}

func (g *PromGauge) With(labelValues ...string) Gauge {
g.lvs = append([]string{}, labelValues...)

return g
g prometheus.Gauge
}

func (g *PromGauge) Set(value float64) {
g.g.WithLabelValues(g.lvs...).Set(value)
}

func (c *PromCounter) With(labelValues ...string) Counter {
c.lvs = append([]string{}, labelValues...)

return c
g.g.Set(value)
}

func (c *PromCounter) Inc() {
c.c.WithLabelValues(c.lvs...).Inc()
}

func (g *NoopGauge) Set(float64) {}
func (g *NoopGauge) With(...string) Gauge { return g }

func (g *NoopCounter) Inc() {}
func (g *NoopCounter) With(...string) Counter { return g }
func (g *Noop) Set(value float64) {}
Loading
Loading