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

Handle k8s service events and trigger SE generation #238

Merged
merged 4 commits into from
Jul 2, 2022

Conversation

aattuluri
Copy link
Contributor

Changes include:

  • Trigger SE generation for k8s service updates
  • Order services by creation time to be more deterministic for multiple service matches
  • Introduce additional delay during bootup before firing sync events for different types
  • Reorder controller creation to start with services, gtps etc and then the deployment and rollouts
  • Disable periodic sync for types other than deployment and rollout

@aattuluri aattuluri requested a review from nirvanagit July 1, 2022 21:38

if err != nil {
return fmt.Errorf(" Error with GlobalTrafficController controller init: %v", err)
return fmt.Errorf(" Error with ServiceController controller init: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: space before Error


if err != nil {
return fmt.Errorf(" Error with DeploymentController controller init: %v", err)
return fmt.Errorf(" Error with GlobalTrafficController controller init: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: space before Error

log.Infof(LogFormat, "Added", "service", obj.Name, sh.ClusterID, "received")
err := HandleEventForService(obj, sh.RemoteRegistry, sh.ClusterID)
if err != nil {
log.Infof(err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Warnf or Errorf instead? (same comment for other related methods)

HandleEventForDeployment(admiral.Update, &deployment, remoteRegistry, clusterName)
}
if common.GetAdmiralParams().ArgoRolloutsEnabled {
rollouts := remoteRegistry.RemoteControllers[clusterName].RolloutController.GetRolloutBySelectorInNamespace(svc.Spec.Selector, svc.Namespace)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check for nil objects for remoteRegistry

for lkey, lvalue := range serviceSelector {
// Rollouts controller adds a dynamic label with name rollouts-pod-template-hash to both active and passive replicasets.
// This dynamic label is not available on the rollout template. Hence ignoring the label with name rollouts-pod-template-hash
if lkey == common.ROLLOUT_POD_HASH_LABEL {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: ROLLOUT_POD_HASH_LABEL -> RolloutPodHashLabel

if lkey == common.ROLLOUT_POD_HASH_LABEL {
continue
}
value, ok := rollout.Spec.Selector.MatchLabels[lkey]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check for nil object.

if !cmp.Equal(serviceCache.Get("ns").Service["ns"][service.Name], service) {
t.Errorf("Incorrect service fount. Diff: %v", cmp.Diff(serviceCache.Get("ns").Service["ns"], service))
if !cmp.Equal(serviceCache.Get("ns")[0], service) {
t.Errorf("Incorrect service fount. Diff: %v", cmp.Diff(serviceCache.Get("ns")[0], service))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: fount -> found

@codecov-commenter
Copy link

Codecov Report

Merging #238 (1ec3ecf) into master (3cd7ac8) will decrease coverage by 0.85%.
The diff coverage is 53.04%.

@@            Coverage Diff             @@
##           master     #238      +/-   ##
==========================================
- Coverage   75.00%   74.15%   -0.86%     
==========================================
  Files          27       27              
  Lines        2613     2647      +34     
==========================================
+ Hits         1960     1963       +3     
- Misses        530      561      +31     
  Partials      123      123              
Impacted Files Coverage Δ
admiral/pkg/clusters/types.go 48.21% <0.00%> (-16.50%) ⬇️
admiral/pkg/controller/admiral/controller.go 38.66% <0.00%> (ø)
admiral/pkg/controller/common/common.go 86.90% <ø> (ø)
admiral/pkg/clusters/registry.go 75.00% <53.57%> (ø)
admiral/pkg/controller/admiral/deployment.go 85.41% <75.00%> (+0.46%) ⬆️
admiral/pkg/controller/admiral/rollouts.go 80.18% <76.47%> (-1.64%) ⬇️
admiral/pkg/controller/admiral/service.go 84.40% <80.76%> (+0.88%) ⬆️
admiral/pkg/clusters/handler.go 61.46% <85.71%> (-0.45%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3cd7ac8...1ec3ecf. Read the comment docs.

@@ -693,12 +693,11 @@ func TestGetServiceForRolloutCanary(t *testing.T) {
selectorMap["app"] = "test"

service := &coreV1.Service{
ObjectMeta: v12.ObjectMeta{Name: SERVICENAME, Namespace: NAMESPACE, CreationTimestamp: v12.NewTime(time.Now())},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: ServiceName, Namespace

@@ -711,15 +710,15 @@ func TestGetServiceForRolloutCanary(t *testing.T) {
service.Spec.Ports = ports

stableService := &coreV1.Service{
ObjectMeta: v12.ObjectMeta{Name: STABLESERVICENAME, Namespace: NAMESPACE},
ObjectMeta: v12.ObjectMeta{Name: STABLESERVICENAME, Namespace: NAMESPACE, CreationTimestamp: v12.NewTime(time.Now().Add(time.Duration(-15)))},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: StableServiceName

Spec: coreV1.ServiceSpec{
Selector: selectorMap,
Ports: ports,
},
}

canaryService := &coreV1.Service{
ObjectMeta: v12.ObjectMeta{Name: CANARYSERVICENAME, Namespace: NAMESPACE},
ObjectMeta: v12.ObjectMeta{Name: CANARYSERVICENAME, Namespace: NAMESPACE, CreationTimestamp: v12.NewTime(time.Now().Add(time.Duration(-15)))},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: CanaryServiceName

var filteredDeployments = make([]k8sAppsV1.Deployment, 0)

for _, deployment := range matchedDeployments.Items {
if deployment.Spec.Selector == nil || deployment.Spec.Selector.MatchLabels == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check for nil values for .Selector and .MatchLabels

if lkey == common.RolloutPodHashLabel {
continue
}
value, ok := rollout.Spec.Selector.MatchLabels[lkey]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the labelSelector parameter in the list option to find deployments matching given labels.

AdmiralIgnoreAnnotation = "admiral.io/ignore"
AdmiralCnameCaseSensitive = "admiral.io/cname-case-sensitive"
BlueGreenRolloutPreviewPrefix = "preview"
RolloutPodHashLabel string = "rollouts-pod-template-hash"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the formatting is off starting line 29.

@aattuluri aattuluri merged commit eeefffa into master Jul 2, 2022
@aattuluri aattuluri deleted the Handle_k8s_service_events branch July 2, 2022 00:39
@aattuluri aattuluri restored the Handle_k8s_service_events branch July 2, 2022 00:48
asushanthk pushed a commit that referenced this pull request Jul 21, 2022
Signed-off-by: sa <sushanth_a@intuit.com>
asushanthk pushed a commit that referenced this pull request Jul 21, 2022
Signed-off-by: sa <sushanth_a@intuit.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants