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

Remove uses of yaml-patch #2212

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

Conversation

lleshchi
Copy link
Contributor

The yaml-patch package is now abandoned. Replaced with gjson and sjson in appropriate places.

HIVE-2397

@lleshchi
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 19, 2024
Copy link
Contributor

openshift-ci bot commented Feb 19, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lleshchi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 19, 2024
Copy link
Contributor

openshift-ci bot commented Feb 19, 2024

@lleshchi: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link

codecov bot commented Feb 19, 2024

Codecov Report

Attention: Patch coverage is 54.92958% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 58.25%. Comparing base (8c54fc9) to head (ba62859).
Report is 43 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2212      +/-   ##
==========================================
- Coverage   58.31%   58.25%   -0.07%     
==========================================
  Files         182      182              
  Lines       25697    25662      -35     
==========================================
- Hits        14986    14950      -36     
+ Misses       9453     9447       -6     
- Partials     1258     1265       +7     
Files Coverage Δ
pkg/clusterresource/builder.go 63.48% <40.00%> (-3.27%) ⬇️
pkg/installmanager/installmanager.go 32.23% <60.78%> (-0.91%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Member

@2uasimojo 2uasimojo left a comment

Choose a reason for hiding this comment

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

This seems sane so far. Most comments along the lines of, "Since we're in here refactoring anyway..."

@@ -419,17 +419,21 @@ func (o *Builder) generateInstallConfigSecret() (*corev1.Secret, error) {
// Remove metadataService field from machinepool platform within installconfig.
// TODO: Remove this once https://bugzilla.redhat.com/show_bug.cgi?id=2098299 has been addressed.
Copy link
Member

Choose a reason for hiding this comment

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

I think this bug was fixed in 4.11, so we may be able to get rid of this hackery altogether.

Comment on lines +428 to +432
return nil, errors.Wrap(err, "error removing metadataService field from install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.aws.metadataService`)
if err != nil {
return nil, errors.Wrap(err, "error removing metadataService field from install-config.yaml")
Copy link
Member

Choose a reason for hiding this comment

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

These error messages should be distinguishable so we know which path broke.

Suggested change
return nil, errors.Wrap(err, "error removing metadataService field from install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.aws.metadataService`)
if err != nil {
return nil, errors.Wrap(err, "error removing metadataService field from install-config.yaml")
return nil, errors.Wrap(err, "error removing metadataService field from compute section of install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.aws.metadataService`)
if err != nil {
return nil, errors.Wrap(err, "error removing metadataService field from controlPlane section of install-config.yaml")

Comment on lines +451 to +455
return nil, errors.Wrap(err, "error removing osImage field from install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.azure.osImage`)
if err != nil {
return nil, errors.Wrap(err, "error removing osImage field from install-config.yaml")
Copy link
Member

Choose a reason for hiding this comment

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

Likewise

Suggested change
return nil, errors.Wrap(err, "error removing osImage field from install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.azure.osImage`)
if err != nil {
return nil, errors.Wrap(err, "error removing osImage field from install-config.yaml")
return nil, errors.Wrap(err, "error removing osImage field from compute section of install-config.yaml")
}
d, err = sjson.DeleteBytes(d, `controlPlane.platform.azure.osImage`)
if err != nil {
return nil, errors.Wrap(err, "error removing osImage field from controlPlane section of install-config.yaml")

@@ -853,7 +851,7 @@ func (m *InstallManager) generateAssets(cd *hivev1.ClusterDeployment, mapPoolsBy
// For details, see HIVE-1802.
// Configure Hive MachineSet manifests with a label for the MachinePool name
var awsClient awsclient.Client
var vpcID string
vpcID := ""
addSecurityGroup := (workerMachinePool != nil) && (metav1.HasAnnotation(workerMachinePool.ObjectMeta, constants.ExtraWorkerSecurityGroupAnnotation))
Copy link
Member

Choose a reason for hiding this comment

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

nit: Seems like we could get rid of the addSecurityGroup bool and just use the non-empty-ness of vpcID to indicate same. It would be one less arg to pass into the already-cluttered patchMachineSetManifest func.

Similarly, I feel like we could get rid of addMPLabel. Inline len(mapPoolsByType) > 0 on L874 and then just let the exists on L1014 filter from there.

@@ -952,7 +933,6 @@ func (m *InstallManager) generateAssets(cd *hivev1.ClusterDeployment, mapPoolsBy
return nil
}

// TODO: Combine this with patchWorkerMachineSetManifest once HIVE-2397 is completed
func writeModifiedBytesToFile(modifiedManifestBytes []byte, d fs.DirEntry, path string, logger log.FieldLogger) error {
if modifiedManifestBytes != nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: could invert this condition with a return and save some indent.

// MachineSet manifest
securityGroupFilterValue := pool.Annotations[constants.ExtraWorkerSecurityGroupAnnotation]

manifestBytesJson, err = sjson.SetBytes(manifestBytesJson, `spec.template.spec.providerSpec.value.securityGroups.0.filters.0.values.0`, securityGroupFilterValue)
Copy link
Member

@2uasimojo 2uasimojo May 2, 2024

Choose a reason for hiding this comment

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

Eh, I think this may be wrong: it is replacing the existing value, whereas the original code is adding.

We start with

          securityGroups:
          - filters:
            - name: tag:Name
              values:
              - test-czcpt-worker-sg

and we want this line to result in

          securityGroups:
          - filters:
            - name: tag:Name
              values:
              - test-czcpt-worker-sg
              - value-from-annotation

but I believe it's instead ending up as

          securityGroups:
          - filters:
            - name: tag:Name
              values:
              - value-from-annotation

Need to confirm via UT. Existing tests are not sufficient: these additions (which are part of the needed rebase) get partway there, but per this comment we still need to add a check for the above.

This seems to do the trick:

Suggested change
manifestBytesJson, err = sjson.SetBytes(manifestBytesJson, `spec.template.spec.providerSpec.value.securityGroups.0.filters.0.values.0`, securityGroupFilterValue)
manifestBytesJson, err = sjson.SetBytes(manifestBytesJson, `spec.template.spec.providerSpec.value.securityGroups.0.filters.0.values.-1`, securityGroupFilterValue)

@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants