Skip to content

Commit

Permalink
Force all GTP events to update only (istio-ecosystem#235) (istio-ecos…
Browse files Browse the repository at this point in the history
…ystem#132)

* Fixes: istio-ecosystem#234

force GTPs to update only

Signed-off-by: Shriram Sharma <shriram_sharma@intuit.com>

* fixed linting errors

Signed-off-by: Shriram Sharma <shriram_sharma@intuit.com>

Co-authored-by: aattuluri <AnilKumar_Attuluri@intuit.com>
  • Loading branch information
2 people authored and GitHub Enterprise committed Jun 24, 2022
1 parent b347994 commit f1a43a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions admiral/pkg/clusters/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ func (dh *DependencyHandler) Deleted(obj *v1.Dependency) {

func (gtp *GlobalTrafficHandler) Added(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Added", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Add, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
}

func (gtp *GlobalTrafficHandler) Updated(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Updated", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Update, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
}

func (gtp *GlobalTrafficHandler) Deleted(obj *v1.GlobalTrafficPolicy) {
log.Infof(LogFormat, "Deleted", "globaltrafficpolicy", obj.Name, gtp.ClusterID, "received")
err := HandleEventForGlobalTrafficPolicy(admiral.Delete, obj, gtp.RemoteRegistry, gtp.ClusterID)
err := HandleEventForGlobalTrafficPolicy(obj, gtp.RemoteRegistry, gtp.ClusterID)
if err != nil {
log.Infof(err.Error())
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func HandleEventForDeployment(event admiral.EventType, obj *k8sAppsV1.Deployment
}

// HandleEventForGlobalTrafficPolicy processes all the events related to GTPs
func HandleEventForGlobalTrafficPolicy(event admiral.EventType, gtp *v1.GlobalTrafficPolicy, remoteRegistry *RemoteRegistry, clusterName string) error {
func HandleEventForGlobalTrafficPolicy(gtp *v1.GlobalTrafficPolicy, remoteRegistry *RemoteRegistry, clusterName string) error {

globalIdentifier := common.GetGtpIdentity(gtp)

Expand All @@ -281,9 +281,7 @@ func HandleEventForGlobalTrafficPolicy(event admiral.EventType, gtp *v1.GlobalTr
// For now we're going to force all the events to update only in order to prevent
// the endpoints from being deleted.
// TODO: Need to come up with a way to prevent deleting default endpoints so that this hack can be removed.
event = admiral.Update

// Use the same function as added deployment function to update and put new service entry in place to replace old one
modifyServiceEntryForNewServiceOrPod(event, env, globalIdentifier, remoteRegistry)
modifyServiceEntryForNewServiceOrPod(admiral.Update, env, globalIdentifier, remoteRegistry)
return nil
}
3 changes: 1 addition & 2 deletions admiral/pkg/clusters/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func TestRolloutHandler(t *testing.T) {
}

func TestHandleEventForGlobalTrafficPolicy(t *testing.T) {
event := admiral.EventType("Add")
p := common.AdmiralParams{
KubeconfigPath: "testdata/fake.config",
}
Expand Down Expand Up @@ -254,7 +253,7 @@ func TestHandleEventForGlobalTrafficPolicy(t *testing.T) {

for _, c := range testcases {
t.Run(c.name, func(t *testing.T) {
err := HandleEventForGlobalTrafficPolicy(event, c.gtp, registry, "testcluster")
err := HandleEventForGlobalTrafficPolicy(c.gtp, registry, "testcluster")
assert.Equal(t, err != nil, c.doesError)
})
}
Expand Down

0 comments on commit f1a43a4

Please sign in to comment.