Skip to content

Commit

Permalink
add missing variables (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvanagit committed Jun 13, 2024
1 parent 74cd140 commit 657f906
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 49 deletions.
22 changes: 11 additions & 11 deletions admiral/pkg/clusters/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (dh *DestinationRuleHandler) Added(ctx context.Context, obj *v1alpha3.Desti
log.Infof(LogFormat, "Add", "DestinationRule", obj.Name, dh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
handleDestinationRuleEvent(ctx, obj, dh, common.Add, common.DestinationRule)
handleDestinationRuleEvent(ctx, obj, dh, common.Add, common.DestinationRuleResourceType)
}

func (dh *DestinationRuleHandler) Updated(ctx context.Context, obj *v1alpha3.DestinationRule) {
Expand All @@ -235,7 +235,7 @@ func (dh *DestinationRuleHandler) Updated(ctx context.Context, obj *v1alpha3.Des
log.Infof(LogFormat, "Update", "DestinationRule", obj.Name, dh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
handleDestinationRuleEvent(ctx, obj, dh, common.Update, common.DestinationRule)
handleDestinationRuleEvent(ctx, obj, dh, common.Update, common.DestinationRuleResourceType)
}

func (dh *DestinationRuleHandler) Deleted(ctx context.Context, obj *v1alpha3.DestinationRule) {
Expand All @@ -247,7 +247,7 @@ func (dh *DestinationRuleHandler) Deleted(ctx context.Context, obj *v1alpha3.Des
log.Infof(LogFormat, "Delete", "DestinationRule", obj.Name, dh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
handleDestinationRuleEvent(ctx, obj, dh, common.Delete, common.DestinationRule)
handleDestinationRuleEvent(ctx, obj, dh, common.Delete, common.DestinationRuleResourceType)
}

func (vh *VirtualServiceHandler) Added(ctx context.Context, obj *v1alpha3.VirtualService) {
Expand All @@ -259,7 +259,7 @@ func (vh *VirtualServiceHandler) Added(ctx context.Context, obj *v1alpha3.Virtua
log.Infof(LogFormat, "Add", "VirtualService", obj.Name, vh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
err := handleVirtualServiceEvent(ctx, obj, vh, common.Add, common.VirtualService)
err := handleVirtualServiceEvent(ctx, obj, vh, common.Add, common.VirtualServiceResourceType)
if err != nil {
log.Error(err)
}
Expand All @@ -274,7 +274,7 @@ func (vh *VirtualServiceHandler) Updated(ctx context.Context, obj *v1alpha3.Virt
log.Infof(LogFormat, "Update", "VirtualService", obj.Name, vh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
err := handleVirtualServiceEvent(ctx, obj, vh, common.Update, common.VirtualService)
err := handleVirtualServiceEvent(ctx, obj, vh, common.Update, common.VirtualServiceResourceType)
if err != nil {
log.Error(err)
}
Expand All @@ -289,7 +289,7 @@ func (vh *VirtualServiceHandler) Deleted(ctx context.Context, obj *v1alpha3.Virt
log.Infof(LogFormat, "Delete", "VirtualService", obj.Name, vh.ClusterID, "Skipping resource from namespace="+obj.Namespace)
return
}
err := handleVirtualServiceEvent(ctx, obj, vh, common.Delete, common.VirtualService)
err := handleVirtualServiceEvent(ctx, obj, vh, common.Delete, common.VirtualServiceResourceType)
if err != nil {
log.Error(err)
}
Expand Down Expand Up @@ -614,7 +614,7 @@ func skipDestructiveUpdate(rc *RemoteController, new *v1alpha3.ServiceEntry, old
return skipDestructive, diff
}

//Diffs only endpoints
// Diffs only endpoints
func getServiceEntryDiff(new *v1alpha3.ServiceEntry, old *v1alpha3.ServiceEntry) (destructive bool, diff string) {
//we diff only if both objects exist
if old == nil || new == nil {
Expand Down Expand Up @@ -728,22 +728,22 @@ func deleteDestinationRule(ctx context.Context, exist *v1alpha3.DestinationRule,
}
}

//nolint
// nolint
func createServiceEntrySkeletion(se networkingv1alpha3.ServiceEntry, name string, namespace string) *v1alpha3.ServiceEntry {
return &v1alpha3.ServiceEntry{Spec: se, ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}}
}

//nolint
// nolint
func createSidecarSkeleton(sidecar networkingv1alpha3.Sidecar, name string, namespace string) *v1alpha3.Sidecar {
return &v1alpha3.Sidecar{Spec: sidecar, ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}}
}

//nolint
// nolint
func createDestinationRuleSkeletion(dr networkingv1alpha3.DestinationRule, name string, namespace string) *v1alpha3.DestinationRule {
return &v1alpha3.DestinationRule{Spec: dr, ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}}
}

//nolint
// nolint
func createVirtualServiceSkeleton(vs networkingv1alpha3.VirtualService, name string, namespace string) *v1alpha3.VirtualService {
return &v1alpha3.VirtualService{Spec: vs, ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}}
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/clusters/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func TestHandleVirtualServiceEvent(t *testing.T) {
//Run the test for every provided case
for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
err := handleVirtualServiceEvent(ctx, c.vs, c.handler, c.event, common.VirtualService)
err := handleVirtualServiceEvent(ctx, c.vs, c.handler, c.event, common.VirtualServiceResourceType)
if err != c.expectedError {
t.Fatalf("Error mismatch, expected %v but got %v", c.expectedError, err)
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {

log.Infof("Informer caches synced for controller=%v, current keys=%v", c.name, c.informer.GetStore().ListKeys())

wait.Until(c.runWorker, 5 * time.Second, stopCh)
wait.Until(c.runWorker, 5*time.Second, stopCh)
}

func (c *Controller) runWorker() {
Expand Down
153 changes: 117 additions & 36 deletions admiral/pkg/controller/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,106 @@ import (
"encoding/gob"
"encoding/hex"
"fmt"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"

v12 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "github.com/istio-ecosystem/admiral/admiral/pkg/apis/admiral/v1"
log "github.com/sirupsen/logrus"
k8sAppsV1 "k8s.io/api/apps/v1"
k8sV1 "k8s.io/api/core/v1"
)

var (
CtxLogFormat = "task=%v name=%v namespace=%s cluster=%s message=%v"
CtxLogFormatWithTime = "task=%v name=%v namespace=%s cluster=%s message=%v txTime=%v"
ConfigWriter = "ConfigWriter"
)

const (
NamespaceKubeSystem = "kube-system"
NamespaceIstioSystem = "istio-system"
Env = "env"
Http = "http"
Grpc = "grpc"
GrpcWeb = "grpc-web"
Http2 = "http2"
DefaultMtlsPort = 15443
DefaultServiceEntryPort = 80
Sep = "."
Dash = "-"
Slash = "/"
DotLocalDomainSuffix = ".svc.cluster.local"
Mesh = "mesh"
MulticlusterIngressGateway = "istio-multicluster-ingressgateway"
LocalAddressPrefix = "240.0"
NodeRegionLabel = "failure-domain.beta.kubernetes.io/region"
SpiffePrefix = "spiffe://"
SidecarEnabledPorts = "traffic.sidecar.istio.io/includeInboundPorts"
Default = "default"
AdmiralIgnoreAnnotation = "admiral.io/ignore"
AdmiralCnameCaseSensitive = "admiral.io/cname-case-sensitive"
BlueGreenRolloutPreviewPrefix = "preview"
RolloutPodHashLabel = "rollouts-pod-template-hash"
RolloutActiveServiceSuffix = "active-service"
RolloutStableServiceSuffix = "stable-service"
WASMPath = "wasmPath"
NamespaceKubeSystem = "kube-system"
NamespaceIstioSystem = "istio-system"
IstioIngressGatewayServiceName = "istio-ingressgateway"
Env = "env"
Http = "http"
Grpc = "grpc"
GrpcWeb = "grpc-web"
Http2 = "http2"
DefaultMtlsPort = 15443
DefaultServiceEntryPort = 80
Sep = "."
Dash = "-"
Slash = "/"
DotLocalDomainSuffix = ".svc.cluster.local"
AssetAlias = "assetAlias"
Mesh = "mesh"
MulticlusterIngressGateway = "istio-multicluster-ingressgateway"
LocalAddressPrefix = "240.0"
NodeRegionLabel = "failure-domain.beta.kubernetes.io/region"
SpiffePrefix = "spiffe://"
SidecarEnabledPorts = "traffic.sidecar.istio.io/includeInboundPorts"
Default = "default"
SidecarInjectAnnotation = "sidecar.istio.io/inject"
AdmiralIgnoreAnnotation = "admiral.io/ignore"
AdmiralEnvAnnotation = "admiral.io/env"
AdmiralCnameCaseSensitive = "admiral.io/cname-case-sensitive"
BlueGreenRolloutPreviewPrefix = "preview"
RolloutPodHashLabel = "rollouts-pod-template-hash"
RolloutActiveServiceSuffix = "active-service"
RolloutStableServiceSuffix = "stable-service"
RolloutRootServiceSuffix = "root-service"
CanaryRolloutCanaryPrefix = "canary"
WASMPath = "wasmPath"
AdmiralProfileDefault = "default"
AdmiralProfilePerf = "perf"
Cartographer = "cartographer"
CreatedBy = "createdBy"
CreatedFor = "createdFor"
CreatedType = "createdType"
CreatedForEnv = "createdForEnv"
IsDisabled = "isDisabled"
TransactionID = "transactionID"
RevisionNumber = "revisionNumber"
EnvoyKind = "EnvoyFilter"
EnvoyApiVersion = "networking.istio.io/v1alpha3"
SlashSTARRule = "/*"
AppThrottleConfigVersion = "v1"
EnvoyFilterLogLevel = "info"
EnvoyFilterLogLocation = "proxy"
EnvoyFilterLogFormat = "json"
ADD = "Add"
UPDATE = "Update"
DELETE = "Delete"
AssetLabel = "asset"

RollingWindow = "ROLLING_WINDOW"

MeshService = "MESH_SERVICE"
Deployment = "deployment"
Rollout = "rollout"
GTP = "gtp"
HAController = "ha-controller"
EventType = "eventType"
ProcessingInProgress = "ProcessingInProgress"
NotProcessed = "NotProcessed"
Processed = "Processed"
DependentClusterOverride = "dependentClusterOverride"
Received = "Received"
Retry = "Retry"
Forget = "Forget"

ClusterName = "clusterName"
EventResourceType = "eventResourceType"
OutlierDetection = "OutlierDetection"
ClientConnectionConfig = "ClientConnectionConfig"

WasmPathValue = "/etc/istio/extensions/dynamicrouter.wasm"
AIREnvSuffix = "-air"
MESHSUFFIX = ".mesh"

LastUpdatedAt = "lastUpdatedAt"
IntuitTID = "intuit_tid"
GTPCtrl = "gtp-ctrl"
)

type Event int
Expand All @@ -56,9 +119,29 @@ const (
type ResourceType string

const (
VirtualService ResourceType = "VirtualService"
DestinationRule ResourceType = "DestinationRule"
ServiceEntry ResourceType = "ServiceEntry"
// Kubernetes/ARGO Resource Types
DeploymentResourceType ResourceType = "Deployment"
RolloutResourceType ResourceType = "Rollout"
ServiceResourceType ResourceType = "Service"
ConfigMapResourceType ResourceType = "ConfigMap"
SecretResourceType ResourceType = "Secret"
NodeResourceType ResourceType = "Node"

// Admiral Resource Types
DependencyResourceType ResourceType = "Dependency"
DependencyProxyResourceType ResourceType = "DependencyProxy"
GlobalTrafficPolicyResourceType ResourceType = "GlobalTrafficPolicy"
RoutingPolicyResourceType ResourceType = "RoutingPolicy"

// Istio Resource Types
VirtualServiceResourceType ResourceType = "VirtualService"
DestinationRuleResourceType ResourceType = "DestinationRule"
ServiceEntryResourceType ResourceType = "ServiceEntry"
EnvoyFilterResourceType ResourceType = "EnvoyFilter"
SidecarResourceType ResourceType = "Sidecar"

// Status
ReceivedStatus = "Received"
)

func GetPodGlobalIdentifier(pod *k8sV1.Pod) string {
Expand Down Expand Up @@ -190,10 +273,9 @@ func ConstructGtpKey(env, identity string) string {
}

func ShouldIgnoreResource(metadata v12.ObjectMeta) bool {
return metadata.Annotations[AdmiralIgnoreAnnotation] == "true" || metadata.Labels[AdmiralIgnoreAnnotation] == "true"
return metadata.Annotations[AdmiralIgnoreAnnotation] == "true" || metadata.Labels[AdmiralIgnoreAnnotation] == "true"
}


func IsServiceMatch(serviceSelector map[string]string, selector *v12.LabelSelector) bool {
if selector == nil || len(selector.MatchLabels) == 0 || len(serviceSelector) == 0 {
return false
Expand Down Expand Up @@ -233,13 +315,14 @@ func GetRoutingPolicyIdentity(rp *v1.RoutingPolicy) string {
func GetRoutingPolicyKey(rp *v1.RoutingPolicy) string {
return ConstructRoutingPolicyKey(GetRoutingPolicyEnv(rp), GetRoutingPolicyIdentity(rp))
}

// this function is exactly same as ConstructGtpKey.
// Not reusing the same function to keep the methods associated with these two objects separate.
func ConstructRoutingPolicyKey(env, identity string) string {
return fmt.Sprintf("%s.%s", env, identity)
}

func GetSha1 (key interface{}) (string, error) {
func GetSha1(key interface{}) (string, error) {
bv, err := GetBytes(key)
if err != nil {
return "", err
Expand All @@ -250,7 +333,6 @@ func GetSha1 (key interface{}) (string, error) {
return sha[0:5], nil
}


func GetBytes(key interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
Expand All @@ -260,4 +342,3 @@ func GetBytes(key interface{}) ([]byte, error) {
}
return buf.Bytes(), nil
}

0 comments on commit 657f906

Please sign in to comment.