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

Removed os.Exec'ing code #2961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rejain456
Copy link

@rejain456 rejain456 commented Aug 27, 2024

Reason for Change:

There was a CRI recently where it appears that when CNS is shelling out to PowerShell, spooling up the whole PowerShell env is quite heavy; thus, we are OOMing the CNS pod. There could be other contributing factors that haven't been identified yet as well.

Issue Fixed:

This pr gets rid of os.Exec'ing a shell (creating a whole new instance of PowerShell) each time and instead replacing the code with calling into windows registry.

Requirements:

Notes:

Work Item: https://msazure.visualstudio.com/One/_workitems/edit/29254102

@rejain456 rejain456 requested a review from a team as a code owner August 27, 2024 22:09
// Connect to the service manager
m, err := mgr.Connect()
if err != nil {
return fmt.Errorf("could not connect to service manager: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Please use errors.Wrap

Comment on lines +322 to +328
for status.State != svc.Stopped {
time.Sleep(500 * time.Millisecond)
status, err = service.Query()
if err != nil {
return fmt.Errorf("could not query service status: %v", err)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This should consult a context.Context for cancelation so that it will not run indefinitely.

@@ -0,0 +1,46 @@
//go:build windows
// +build windows
Copy link
Member

Choose a reason for hiding this comment

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

This module requires at least Go 1.18 to build, so we no longer need to add // +build windows. The //go:build pragma is the only one needed.

key registry.Key
}

func (r *WindowsRegistry) OpenKey(k registry.Key, path string, access uint32) (RegistryKey, error) {
Copy link
Member

Choose a reason for hiding this comment

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

k is unused here--I don't think that's intentional. Granted, we're probably always going to use HKLM, but who knows? If we're making a generic wrapper, I'd like to be able to, say, edit some keys in HKCU.

Copy link
Contributor

Choose a reason for hiding this comment

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

as someone with no understanding of win reg, you could be making these up and I would have no idea 😂

Copy link
Member

Choose a reason for hiding this comment

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

@rbtr this is cursed knowledge from working summers at my high school playing student sysadmin :-P The Norton Ghosts still haunt me.

Comment on lines +36 to +37
value, valType, err := k.key.GetStringValue(name)
return value, valType, err
Copy link
Member

Choose a reason for hiding this comment

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

This simplifies to

Suggested change
value, valType, err := k.key.GetStringValue(name)
return value, valType, err
return k.key.GetStringValue(name)

Comment on lines +50 to +52
func (k *MockRegistryKey) Close() error {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it be incorrect to not close a key? It might be worth adding some bookkeeping in here to make sure it's getting called if so.

// OpenKey opens a mock registry key.
func (r *MockRegistry) OpenKey(k registry.Key, path string, access uint32) (RegistryKey, error) {
// Directly check if the key exists in the mock registry by its path
if key, exists := r.Keys[path]; exists {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Traditionally, the Go community writes the second parameter here as ok.

Suggested change
if key, exists := r.Keys[path]; exists {
if key, ok := r.Keys[path]; ok {

Comment on lines +170 to +172
// mockExecClient.SetPowershellCommandResponder(func(_ string) (string, error) {
// return "False", nil
// })
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to remove these. Dead code can be found and resurrected with git if necessary.

@rbtr rbtr added cns Related to CNS. needs-backport Change needs to be backported to previous release trains labels Aug 28, 2024
@rbtr
Copy link
Contributor

rbtr commented Aug 28, 2024

while i'm thinking about it we'll probably want to backport this to 1.4/1.5 since those are still a substantial install base

Copy link

This pull request is stale because it has been open for 2 weeks with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the stale Stale due to inactivity. label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cns Related to CNS. needs-backport Change needs to be backported to previous release trains stale Stale due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants