-
Notifications
You must be signed in to change notification settings - Fork 50
test: Add client side install method for restoring Config Sync #1834
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
base: main
Are you sure you want to change the base?
Changes from all commits
313a440
77a9062
9e508cc
7f771ee
0c6dcc9
9b56f3b
e8cc294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,6 +78,16 @@ const ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shortSyncPollingPeriod = 5 * time.Second | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// InstallMethod defines how Config Sync should be installed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type InstallMethod string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// InstallMethodApply uses server-side apply (default) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InstallMethodApply InstallMethod = "apply" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// InstallMethodUpdate uses client-side update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
InstallMethodUpdate InstallMethod = "update" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
var ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// baseDir is the path to the Nomos repository root from test case files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -230,16 +240,36 @@ func parseConfigSyncManifests(nt *NT) ([]client.Object, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// InstallConfigSync installs ConfigSync on the test cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func InstallConfigSync(nt *NT) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nt.T.Log("[SETUP] Installing Config Sync") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func InstallConfigSync(nt *NT, method InstallMethod) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nt.T.Log("[SETUP] Installing Config Sync using method: ", method) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
objs, err := parseConfigSyncManifests(nt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, o := range objs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nt.T.Logf("installConfigSync obj: %v", core.GKNN(o)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := nt.KubeClient.Apply(o); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
switch method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case InstallMethodApply: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := nt.KubeClient.Apply(o); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
case InstallMethodUpdate: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
currentObj := o.DeepCopyObject().(client.Object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type assertion
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A DeepCopy should not be necessary here for every object, can this be switched to populating an empty object (e.g. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := nt.KubeClient.Get(currentObj.GetName(), currentObj.GetNamespace(), currentObj); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if apierrors.IsNotFound(err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := nt.KubeClient.Create(o); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Attach existing resourceVersion to the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment doesn't add much context, I'd suggest explaining "why" it's attaching the In this instance, the current state of the object on the cluster does not matter and the intent is to fully update to the original configuration declared in the manifest |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o.SetResourceVersion(currentObj.GetResourceVersion()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := nt.KubeClient.Update(o); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+267
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting the resource version on the object being updated could cause conflicts if the object was modified between the Get and Update operations. Consider using a retry mechanism or server-side apply to handle concurrent modifications more reliably.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
It doesn't look like this is currently the default. If the intent is to retain default behavior, I'd suggest updating the function signature to accept a variadic list of options (for example
func InstallConfigSync(nt *NT, opts ...InstallConfigSyncOpts) error {
)