-
Notifications
You must be signed in to change notification settings - Fork 124
CSPL-542: Utility to get and update secret object #265
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
Conversation
CSPL-879: Utility to apply updated spec
MonitoringConsolePod = "splunk-%s-monitoring-console-%d" | ||
|
||
// SecretObject Secret object Template | ||
SecretObject = "splunk-%s-secret" |
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.
Nit: Change to SecretObjectName ?
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.
I use the secretObjectName in the function itself after i fill in the 'namespace'. Think it would be ok to keep as it is
return false | ||
} | ||
return true | ||
|
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.
Nit: extra line unnecessary here?
secretName := fmt.Sprintf(SecretObject, ns) | ||
secret := newSecretSpec(ns, secretName, data) | ||
//Update object using spec | ||
err := deployment.updateCR(secret) |
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.
Does updateCR take care of a case where secret object is not present?
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.
Yes. If the object is not present. It creates the object with the details specified
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.
And if it does exist, does it update? If yes we are good.
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.
Yup. This fcn is mainly to update it. But does take care of the scenario when object is not present
|
||
//Convert object to map for update | ||
var data map[string][]byte | ||
err = json.Unmarshal([]byte(out), &data) |
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.
Curious, how does the unmarshal convert the variable out to a map? And what data type is out?
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.
Out is a Json object. Unmarshal will convert it to a map. Tested it out when running the local changes
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.
Does the input to unmarshal need to be of a certain type for it to convert it to a map? i.e []byte? How does it determine the key and value pairs?
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.
So the object is initially built into a json out of the exec.command() function using the struct defined at the top. Here we take care of any extra fields that might have come accidentally. Post that its simple to convert from json to map and then to update
Needs https://github.com/splunk/splunk-operator/pull/262/files to be merged to work.
Tested locally:
[1] {"level":"info","ts":1614362873.529494,"msg":"Checking status of Monitoring Console Pod"}
[1] {"level":"info","ts":1614362873.7195148,"msg":"MC statefulset found","POD":"splunk-smoke-ob-monitoring-console","READY":"1/1"}
[1] {"level":"info","ts":1614362873.939373,"msg":"MC Pod Found","POD":"splunk-smoke-ob-monitoring-console-0","READY":"1/1"}
[1] {"level":"info","ts":1614362874.1707141,"msg":"NAME READY STATUS RESTARTS AGE"}
[1] {"level":"info","ts":1614362874.170743,"msg":"splunk-op-smoke-ob-5b6c9f9d44-fhxm8 1/1 Running 0 5m"}
[1] {"level":"info","ts":1614362874.1707468,"msg":"splunk-smoke-ob-fmp-license-master-0 1/1 Running 0 4m53s"}
[1] {"level":"info","ts":1614362874.17075,"msg":"splunk-smoke-ob-fmp-standalone-0 1/1 Running 0 4m52s"}
[1] {"level":"info","ts":1614362874.170753,"msg":"splunk-smoke-ob-monitoring-console-0 1/1 Running 0 96s"}
[1] {"level":"info","ts":1614362874.170756,"msg":""}
[1] '{"hec_token":"MEIyNjIwQTEtNzc1QS0yMDc3LTY0NUItQkY0OTA3NjM3QkZF","idxc_secret":"WENsU3FSTVcxdzhQRzFmSmtwWkhXelEy","pass4SymmKey":"dmY3MDk2ZlRXZWVtQ2hDY1NOaTZQeWI1","password":"cFpvRzVUeVp4Y0pSck1YUXhRd3VWUm1k","shc_secret":"Sk1ZS1VITTdVQklLWVZQUGVLaW1nVzd2"}'
[1] rest_response
[1] {MEIyNjIwQTEtNzc1QS0yMDc3LTY0NUItQkY0OTA3NjM3QkZF WENsU3FSTVcxdzhQRzFmSmtwWkhXelEy dmY3MDk2ZlRXZWVtQ2hDY1NOaTZQeWI1 cFpvRzVUeVp4Y0pSck1YUXhRd3VWUm1k Sk1ZS1VITTdVQklLWVZQUGVLaW1nVzd2}
[1] '{"hec_token":"ZEdWemRGOTJZV3gxWlE9PQ==","idxc_secret":"WENsU3FSTVcxdzhQRzFmSmtwWkhXelEy","pass4SymmKey":"dmY3MDk2ZlRXZWVtQ2hDY1NOaTZQeWI1","password":"cFpvRzVUeVp4Y0pSck1YUXhRd3VWUm1k","shc_secret":"Sk1ZS1VITTdVQklLWVZQUGVLaW1nVzd2"}'
[1] rest_response
[1] {ZEdWemRGOTJZV3gxWlE9PQ== WENsU3FSTVcxdzhQRzFmSmtwWkhXelEy dmY3MDk2ZlRXZWVtQ2hDY1NOaTZQeWI1 cFpvRzVUeVp4Y0pSck1YUXhRd3VWUm1k Sk1ZS1VITTdVQklLWVZQUGVLaW1nVzd2}