-
Notifications
You must be signed in to change notification settings - Fork 361
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
fix: do not compare all svc.spec for user modified scene #1342
fix: do not compare all svc.spec for user modified scene #1342
Conversation
d163cca
to
1ddf9d3
Compare
Codecov Report
@@ Coverage Diff @@
## main #1342 +/- ##
==========================================
+ Coverage 62.44% 62.55% +0.11%
==========================================
Files 79 79
Lines 11084 11088 +4
==========================================
+ Hits 6921 6936 +15
+ Misses 3707 3697 -10
+ Partials 456 455 -1
|
7ea2c83
to
79b9cf8
Compare
79b9cf8
to
4cbb1a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cc @arkodg for second review
4cbb1a0
to
f2595e9
Compare
@@ -122,7 +124,7 @@ func (i *Instance) CreateOrUpdateService(ctx context.Context, svc *corev1.Servic | |||
} | |||
} else { | |||
// Update if current value is different. | |||
if !reflect.DeepEqual(svc.Spec, current.Spec) { | |||
if !utils.CompareSvc(svc, current) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are two bugs associated with this logic
-
we are comparing the entire
Spec
here, instead we should be comparing all the fields the infra layer sets or skip the fields the infra layer does not set https://pkg.go.dev/k8s.io/api/core/v1#ServiceSpec. -
when updating the service, we need to set immutable fields like
ClusterIP
andClusterIPs
// clusterIP is the IP address of the service and is usually assigned
// randomly. If an address is specified manually, is in-range (as per
// system configuration), and is not in use, it will be allocated to the
// service; otherwise creation of the service will fail. This field may not
// be changed through updates unless the type field is also being changed
// to ExternalName (which requires this field to be blank) or the type
// field is being changed from ExternalName (in which case this field may
// optionally be specified, as describe above). Valid values are "None",
// empty string (""), or a valid IP address. Setting this to "None" makes a
// "headless service" (no virtual IP), which is useful when direct endpoint
// connections are preferred and proxying is not required. Only applies to
// types ClusterIP, NodePort, and LoadBalancer. If this field is specified
// when creating a Service of type ExternalName, creation will fail. This
// field will be wiped when updating a Service to type ExternalName.
// More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies
// +optional
ClusterIP [string](https://pkg.go.dev/builtin#string) `json:"clusterIP,omitempty" protobuf:"bytes,3,opt,name=clusterIP"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1, ok, i'll add imutable fields compare we set.
2, when updating the svc, is these be better that just patch what we need rather than set everything to the new svc?
3, actually,when we use loadbalacer by default, svc.Spec.ports[*].nodePort will be set an random number by k8s, so it's not just about user modified the svc type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reg 2. Patch
is fine, my only request is to keep the code simple so it can be enhanced with more fields in the future
Reg 3. its okay to undo what user did, to solve this, we must
- support
Nodeport
natively - support BYO Envoy Svc and Envoy Deployment and disable managed infra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise another pr for support NodePort
natively might be a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure please go ahead @spwangxp
|
||
// CompareSvc Only compare the selector and ports(not include nodePort) in case user have modified for some scene. | ||
func CompareSvc(newSvc, originalSvc *corev1.Service) bool { | ||
return cmp.Equal(newSvc.Spec.Selector, originalSvc.Spec.Selector) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the infra layer also sets Type
and SessionAffinity
func ExpectedServiceSpec(serviceType *egcfgv1a1.ServiceType) corev1.ServiceSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something for the future, we should find a sane way to ensure we check what we set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any need to update svc type rather than follow user's setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some comments above, Patch
is fine as long as its easy to mantain
thanks for highlighting this bug @spwangxp, added some comments |
also @spwangxp if you are using service type |
f2595e9
to
aae2408
Compare
@qicz can you take a first pass ? with the recent refactor want to make sure the logic lives in the right place, TIA |
Signed-off-by: spwangxp <[email protected]>
aae2408
to
87488d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pls approve ci @arkodg
I got this @qicz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arkodg for final review.
Signed-off-by: spwangxp <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
/hold can we compare the entire I've raised two issues to track your use case @spwangxp
|
1, actual |
every time an API change is made to the |
check and remove ignored field should de done when |
The ignore list shouldnt change in the codebase, but should only only increase whenever upstream K8s API adds a dynamic field into the |
1, add some comment on
check list:
|
afaik we should only ignore
since they are generated by K8s |
+1 since this makes it easy to maintain / not need to remember this, otherwise lgtm |
Signed-off-by: spwangxp <[email protected]>
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
Thanks for working on it @spwangxp
Signed-off-by: spwangxp <[email protected]>
ci needs to retrigger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for considering all the suggestions !
What type of PR is this?
fix: #1340What this PR does / why we need it:
if not, the ir will encounter an error when update svc.
for example, user A deployed an envoyproxy, and set the svc type to NodePort instead of LoadBalancer, then the gateway restart, the check will always be error.
Which issue(s) this PR fixes:
Fixes #1340