Skip to content

Commit

Permalink
add err checks on registry calls
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Tay <[email protected]>
  • Loading branch information
Ryan Tay committed Dec 11, 2024
1 parent c84ca32 commit 23e3d42
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 18 deletions.
15 changes: 12 additions & 3 deletions admiral/pkg/clusters/clientconnectionconfig_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ func (c *ClientConnectionConfigHandler) Added(ctx context.Context,
log.Infof(
LogFormat, common.Add, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, "received")
if common.IsAdmiralStateSyncerMode() {
c.RemoteRegistry.RegistryClient.PutCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string), clientConnectionSettings)
err := c.RemoteRegistry.RegistryClient.PutCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string), clientConnectionSettings)
if err != nil {
log.Errorf(LogFormat, common.Add, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, "failed to put "+common.ClientConnectionConfig+" custom data")
}
}
err := HandleEventForClientConnectionConfig(
ctx, admiral.Add, clientConnectionSettings, c.RemoteRegistry, c.ClusterID, modifyServiceEntryForNewServiceOrPod)
Expand All @@ -94,7 +97,10 @@ func (c *ClientConnectionConfigHandler) Updated(
log.Infof(
LogFormat, common.Update, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, common.ReceivedStatus)
if common.IsAdmiralStateSyncerMode() {
c.RemoteRegistry.RegistryClient.PutCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string), clientConnectionSettings)
err := c.RemoteRegistry.RegistryClient.PutCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string), clientConnectionSettings)
if err != nil {
log.Errorf(LogFormat, common.Update, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, "failed to put "+common.ClientConnectionConfig+" custom data")
}
}
err := HandleEventForClientConnectionConfig(
ctx, admiral.Update, clientConnectionSettings, c.RemoteRegistry, c.ClusterID, modifyServiceEntryForNewServiceOrPod)
Expand All @@ -110,7 +116,10 @@ func (c *ClientConnectionConfigHandler) Deleted(
log.Infof(
LogFormat, common.Delete, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, common.ReceivedStatus)
if common.IsAdmiralStateSyncerMode() {
c.RemoteRegistry.RegistryClient.DeleteCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string))
err := c.RemoteRegistry.RegistryClient.DeleteCustomData(c.ClusterID, clientConnectionSettings.Namespace, clientConnectionSettings.Name, common.ClientConnectionConfig, ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, common.Delete, common.ClientConnectionConfig, clientConnectionSettings.Name, c.ClusterID, "failed to delete "+common.ClientConnectionConfig+" custom data")
}
}
err := HandleEventForClientConnectionConfig(
ctx, admiral.Update, clientConnectionSettings, c.RemoteRegistry, c.ClusterID, modifyServiceEntryForNewServiceOrPod)
Expand Down
10 changes: 8 additions & 2 deletions admiral/pkg/clusters/clientdiscovery_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ func HandleEventForClientDiscovery(ctx context.Context, event admiral.EventType,
ctx = context.WithValue(ctx, "eventResourceType", obj.Type)

if event != admiral.Delete {
remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, obj.Type, ctx.Value("txId").(string), obj)
err := remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, obj.Type, ctx.Value("txId").(string), obj)
if err != nil {
ctxLogger.Errorf(common.CtxLogFormat, event, obj.Name, obj.Namespace, clusterName, "failed to put "+obj.Type+" hosting data for identity="+globalIdentifier)
}
} else {
remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, obj.Type, ctx.Value("txId").(string))
err := remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, obj.Type, ctx.Value("txId").(string))
if err != nil {
ctxLogger.Errorf(common.CtxLogFormat, event, obj.Name, obj.Namespace, clusterName, "failed to delete "+obj.Type+" hosting data for identity="+globalIdentifier)
}
}

if remoteRegistry.AdmiralCache != nil {
Expand Down
10 changes: 8 additions & 2 deletions admiral/pkg/clusters/deployment_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ func HandleEventForDeployment(ctx context.Context, event admiral.EventType, obj
if common.IsAdmiralStateSyncerMode() {
// the globalIdentifier is partition + "." + assetAlias, not just assetAlias
if event != admiral.Delete {
remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Deployment, ctx.Value("txId").(string), obj)
err := remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Deployment, ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, event, common.DeploymentResourceType, obj.Name, clusterName, "failed to put "+common.Deployment+" hosting data for identity="+globalIdentifier)
}
} else {
remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Deployment, ctx.Value("txId").(string))
err := remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Deployment, ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, event, common.DeploymentResourceType, obj.Name, clusterName, "failed to delete "+common.Deployment+" hosting data for identity="+globalIdentifier)
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions admiral/pkg/clusters/globaltraffic_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (g *globalTrafficCache) Delete(identity string, environment string) error {
func (gtp *GlobalTrafficHandler) Added(ctx context.Context, obj *v1.GlobalTrafficPolicy) error {
log.Infof(LogFormat, "Added", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
if common.IsAdmiralStateSyncerMode() {
gtp.RemoteRegistry.RegistryClient.PutCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string), obj)
err := gtp.RemoteRegistry.RegistryClient.PutCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, "Added", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "failed to put GlobalTrafficPolicy custom data")
}
}
err := HandleEventForGlobalTrafficPolicy(ctx, admiral.Add, obj, gtp.RemoteRegistry, gtp.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand All @@ -79,7 +82,10 @@ func (gtp *GlobalTrafficHandler) Added(ctx context.Context, obj *v1.GlobalTraffi
func (gtp *GlobalTrafficHandler) Updated(ctx context.Context, obj *v1.GlobalTrafficPolicy) error {
log.Infof(LogFormat, "Updated", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
if common.IsAdmiralStateSyncerMode() {
gtp.RemoteRegistry.RegistryClient.PutCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string), obj)
err := gtp.RemoteRegistry.RegistryClient.PutCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, "Updated", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "failed to put GlobalTrafficPolicy custom data")
}
}
err := HandleEventForGlobalTrafficPolicy(ctx, admiral.Update, obj, gtp.RemoteRegistry, gtp.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand All @@ -91,7 +97,10 @@ func (gtp *GlobalTrafficHandler) Updated(ctx context.Context, obj *v1.GlobalTraf
func (gtp *GlobalTrafficHandler) Deleted(ctx context.Context, obj *v1.GlobalTrafficPolicy) error {
log.Infof(LogFormat, "Deleted", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
if common.IsAdmiralStateSyncerMode() {
gtp.RemoteRegistry.RegistryClient.DeleteCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string))
err := gtp.RemoteRegistry.RegistryClient.DeleteCustomData(gtp.ClusterID, obj.Namespace, obj.Name, "GlobalTrafficPolicy", ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, "Deleted", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "failed to delete GlobalTrafficPolicy custom data")
}
}
err := HandleEventForGlobalTrafficPolicy(ctx, admiral.Delete, obj, gtp.RemoteRegistry, gtp.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand Down
15 changes: 12 additions & 3 deletions admiral/pkg/clusters/outlierdetection_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func (cache *outlierDetectionCache) Delete(identity string, env string) error {
func (od OutlierDetectionHandler) Added(ctx context.Context, obj *v1.OutlierDetection) error {
log.Infof(LogFormat, common.Add, common.OutlierDetection, obj.Name, od.ClusterID, common.ReceivedStatus)
if common.IsAdmiralStateSyncerMode() {
od.RemoteRegistry.RegistryClient.PutCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string), obj)
err := od.RemoteRegistry.RegistryClient.PutCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, common.Add, common.OutlierDetection, obj.Name, od.ClusterID, "failed to put "+common.OutlierDetection+" custom data")
}
}
err := HandleEventForOutlierDetection(ctx, admiral.EventType(common.Add), obj, od.RemoteRegistry, od.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand All @@ -81,7 +84,10 @@ func (od OutlierDetectionHandler) Added(ctx context.Context, obj *v1.OutlierDete
func (od OutlierDetectionHandler) Updated(ctx context.Context, obj *v1.OutlierDetection) error {
log.Infof(LogFormat, common.Update, common.OutlierDetection, obj.Name, od.ClusterID, common.ReceivedStatus)
if common.IsAdmiralStateSyncerMode() {
od.RemoteRegistry.RegistryClient.PutCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string), obj)
err := od.RemoteRegistry.RegistryClient.PutCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, common.Update, common.OutlierDetection, obj.Name, od.ClusterID, "failed to put "+common.OutlierDetection+" custom data")
}
}
err := HandleEventForOutlierDetection(ctx, admiral.Update, obj, od.RemoteRegistry, od.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand All @@ -93,7 +99,10 @@ func (od OutlierDetectionHandler) Updated(ctx context.Context, obj *v1.OutlierDe
func (od OutlierDetectionHandler) Deleted(ctx context.Context, obj *v1.OutlierDetection) error {
log.Infof(LogFormat, common.Delete, common.OutlierDetection, obj.Name, od.ClusterID, common.ReceivedStatus)
if common.IsAdmiralStateSyncerMode() {
od.RemoteRegistry.RegistryClient.DeleteCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string))
err := od.RemoteRegistry.RegistryClient.DeleteCustomData(od.ClusterID, obj.Namespace, obj.Name, common.OutlierDetection, ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, common.Delete, common.OutlierDetection, obj.Name, od.ClusterID, "failed to delete "+common.OutlierDetection+" custom data")
}
}
err := HandleEventForOutlierDetection(ctx, admiral.Update, obj, od.RemoteRegistry, od.ClusterID, modifyServiceEntryForNewServiceOrPod)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions admiral/pkg/clusters/rollout_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ func HandleEventForRollout(ctx context.Context, event admiral.EventType, obj *ar
ctx = context.WithValue(ctx, "eventResourceType", common.Rollout)

if event != admiral.Delete {
remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Rollout, ctx.Value("txId").(string), obj)
err := remoteRegistry.RegistryClient.PutHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Rollout, ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, event, common.RolloutResourceType, obj.Name, clusterName, "failed to put "+common.Rollout+" hosting data for identity="+globalIdentifier)
}
} else {
remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Rollout, ctx.Value("txId").(string))
err := remoteRegistry.RegistryClient.DeleteHostingData(clusterName, obj.Namespace, obj.Name, globalIdentifier, common.Rollout, ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, event, common.RolloutResourceType, obj.Name, clusterName, "failed to delete "+common.Rollout+" hosting data for identity="+globalIdentifier)
}
}

if remoteRegistry.AdmiralCache != nil {
Expand Down
28 changes: 28 additions & 0 deletions admiral/pkg/clusters/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ func handleServiceEventForDeployment(
eventType = admiral.Update
ctx = context.WithValue(ctx, common.EventType, admiral.Update)
serviceController.Cache.Delete(svc)
if common.IsAdmiralStateSyncerMode() {
err = remoteRegistry.RegistryClient.DeleteHostingData(clusterName, svc.Namespace, svc.Name, common.GetDeploymentGlobalIdentifier(&deployment), svc.Kind, ctx.Value("txId").(string))
if err != nil {
allErrors = common.AppendError(allErrors, err)
}
}
}
}

// Why are we deleting the svc and then adding it back in case of delete?
if common.IsAdmiralStateSyncerMode() {
err := remoteRegistry.RegistryClient.PutHostingData(clusterName, svc.Namespace, svc.Name, common.GetDeploymentGlobalIdentifier(&deployment), svc.Kind, ctx.Value("txId").(string), svc)
if err != nil {
allErrors = common.AppendError(allErrors, err)
}
}

Expand Down Expand Up @@ -212,6 +226,20 @@ func handleServiceEventForRollout(
eventType = admiral.Update
ctx = context.WithValue(ctx, common.EventType, admiral.Update)
serviceController.Cache.Delete(svc)
if common.IsAdmiralStateSyncerMode() {
err = remoteRegistry.RegistryClient.DeleteHostingData(clusterName, svc.Namespace, svc.Name, common.GetRolloutGlobalIdentifier(&rollout), svc.Kind, ctx.Value("txId").(string))
if err != nil {
allErrors = common.AppendError(allErrors, err)
}
}
}
}

// Why are we deleting the svc and then adding it back in case of delete?
if common.IsAdmiralStateSyncerMode() {
err := remoteRegistry.RegistryClient.PutHostingData(clusterName, svc.Namespace, svc.Name, common.GetRolloutGlobalIdentifier(&rollout), svc.Kind, ctx.Value("txId").(string), svc)
if err != nil {
allErrors = common.AppendError(allErrors, err)
}
}

Expand Down
15 changes: 12 additions & 3 deletions admiral/pkg/clusters/virtualservice_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ func (vh *VirtualServiceHandler) Added(ctx context.Context, obj *v1alpha3.Virtua
return nil
}
if common.IsAdmiralStateSyncerMode() {
vh.remoteRegistry.RegistryClient.PutCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string), obj)
err := vh.remoteRegistry.RegistryClient.PutCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, common.Add, "VirtualService", obj.Name, vh.clusterID, "failed to update VirtualService custom data")
}
}
return vh.handleVirtualServiceEvent(ctx, obj, common.Add)
}
Expand All @@ -106,7 +109,10 @@ func (vh *VirtualServiceHandler) Updated(ctx context.Context, obj *v1alpha3.Virt
return nil
}
if common.IsAdmiralStateSyncerMode() {
vh.remoteRegistry.RegistryClient.PutCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string), obj)
err := vh.remoteRegistry.RegistryClient.PutCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string), obj)
if err != nil {
log.Errorf(LogFormat, common.Update, "VirtualService", obj.Name, vh.clusterID, "failed to update VirtualService custom data")
}
}
return vh.handleVirtualServiceEvent(ctx, obj, common.Update)
}
Expand All @@ -124,7 +130,10 @@ func (vh *VirtualServiceHandler) Deleted(ctx context.Context, obj *v1alpha3.Virt
return nil
}
if common.IsAdmiralStateSyncerMode() {
vh.remoteRegistry.RegistryClient.DeleteCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string))
err := vh.remoteRegistry.RegistryClient.DeleteCustomData(vh.clusterID, obj.Namespace, obj.Name, "VirtualService", ctx.Value("txId").(string))
if err != nil {
log.Errorf(LogFormat, common.Delete, "VirtualService", obj.Name, vh.clusterID, "failed to delete VirtualService custom data")
}
}
return vh.handleVirtualServiceEvent(ctx, obj, common.Delete)
}
Expand Down

0 comments on commit 23e3d42

Please sign in to comment.