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

MULTIARCH-5058: Implement the node affinity scoring specs in the ClusterPodPlacementConfig #369

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

Conversation

pkenchap
Copy link

Task to add the nodeAffinityScoring for ClusterPodPlacemetnConfig API specs can be updated as in the following to host a skeleton of plugins, currently implementing only the nodeAffinityScoring.

Example:

spec:
  plugins:
    nodeAffinityScoring:
        enabled: true
        platforms:
            - architecture: amd64
              # os: linux # TODO: this structure can support the os field in the future (e.g., for win containers)
              weight: 100

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Nov 20, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented Nov 20, 2024

@pkenchap: This pull request references MULTIARCH-5058 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.18.0" version, but no target version was set.

In response to this:

Task to add the nodeAffinityScoring for ClusterPodPlacemetnConfig API specs can be updated as in the following to host a skeleton of plugins, currently implementing only the nodeAffinityScoring.

Example:

spec:
 plugins:
   nodeAffinityScoring:
       enabled: true
       platforms:
           - architecture: amd64
             # os: linux # TODO: this structure can support the os field in the future (e.g., for win containers)
             weight: 100

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 openshift-eng/jira-lifecycle-plugin repository.

@pkenchap
Copy link
Author

/assign @pkenchap

Copy link

openshift-ci bot commented Nov 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign annazivkovic for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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


const (
// PluginName for NodeAffinityScoring.
PluginName = "NodeAffinityScoring"
Copy link
Member

Choose a reason for hiding this comment

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

Hi @pkenchap, a few initial notes of review:

  • can we have two separate files in the common/plugins folder? One for the BasePlugin, another for the NodeAffinityScoring plugin.
  • Can we also add an interface IBasePlugin with one method for now, Name() string?
  • The interface IBasePlugin and struct BasePlugin can stay on the common/plugins/base_plugin.go
  • PluginName should be renamed to NodeAffinityScoringPluginName so that other plugins can have their meaningful constant name accordingly.
  • I see all the fields (Enabled, Architecture, Weight) are tagged as omitempty. I believe we should set them as always required. The only omitempty fields should the plugins stanza and each possible plugin's stanza's key within it.
  • Let's set kubebuilder annotations to configure validation: https://book.kubebuilder.io/reference/markers/crd-validation

Copy link
Author

Choose a reason for hiding this comment

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

Sure , I will make these changes . Thanks for the suggestions .

}

// Score calculates the score of a node based on node affinity and architecture
func (n *NodeAffinityScoring) ArchWeight(ctx context.Context, pod *v1.Pod, node *v1.Node) int64 {
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this function?

// of the pods. If left empty, all the namespaces are considered.
// The default sample allows to exclude all the namespaces where the
// +optional
Plugins plugins.NodeAffinityScoring `json:"plugins,omitempty"`
Copy link
Member

@aleskandro aleskandro Nov 20, 2024

Choose a reason for hiding this comment

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

Plugins should be a more generic structure plugins.Plugins (and probably a pointer).

Something like

type Plugins struct {
  NodeAffinityScoring *NodeAffinityScoring `json:"nodeAffinityScording,omitempty"
  // Future plugins
}


// NodeAffinityScoring is the plugin that implements the ScorePlugin interface
type NodeAffinityScoring struct {
Base PluginBase `json:"Base,omitempty" protobuf:"bytes,1,opt,name=Base"`
Copy link
Member

@aleskandro aleskandro Nov 20, 2024

Choose a reason for hiding this comment

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

Let's use embedding to embed the PluginBase fields

Suggested change
Base PluginBase `json:"Base,omitempty" protobuf:"bytes,1,opt,name=Base"`
PluginBase `json:"Base,omitempty" protobuf:"bytes,1,opt,name=Base"`

Copy link
Member

Choose a reason for hiding this comment

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

…terPodPlacementConfig

Signed-off-by: Punith Kenchappa <[email protected]>
Copy link

openshift-ci bot commented Nov 21, 2024

@pkenchap: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ocp417-e2e-gcp 7994305 link true /test ocp417-e2e-gcp
ci/prow/bundle 7994305 link true /test bundle
ci/prow/unit 7994305 link true /test unit
ci/prow/ocp417-ci-index-multiarch-tuning-operator-bundle 7994305 link true /test ocp417-ci-index-multiarch-tuning-operator-bundle

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-sigs/prow repository. I understand the commands that are listed here.

// NodeAffinityScoring is the plugin that implements the ScorePlugin interface.
type NodeAffinityScoring struct {
// Base is a required field for enabling/disabling the plugin.
Base PluginBase `json:"base" protobuf:"bytes,1,opt,name=base" kubebuilder:"validation:Required"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Base PluginBase `json:"base" protobuf:"bytes,1,opt,name=base" kubebuilder:"validation:Required"`
PluginBase `json:"base" protobuf:"bytes,1,opt,name=base" kubebuilder:"validation:Required"`

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't embedding suffice here?

// Architecture must be a non-empty string.
Architecture string `json:"architecture" protobuf:"bytes,1,rep,name=architecture" kubebuilder:"validation:Required"`
// Weight must be a non-negative integer.
Weight int `json:"weight" protobuf:"bytes,2,rep,name=weight" kubebuilder:"validation:Required,validation:Minimum=0"`
Copy link
Member

Choose a reason for hiding this comment

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

are the kubebuilder tags verified?

We've always set them as comments above the field:

Suggested change
Weight int `json:"weight" protobuf:"bytes,2,rep,name=weight" kubebuilder:"validation:Required,validation:Minimum=0"`
// +kubebuilder:validation:Minimum:=0
// +kubebuilder:validation:Required
Weight int `json:"weight" protobuf:"bytes,2,rep,name=weight"`

(Look at similar ones in the code)


const (
// PluginName for NodeAffinityScoring.
PluginName = "NodeAffinityScoringPluginName"
Copy link
Member

@aleskandro aleskandro Nov 21, 2024

Choose a reason for hiding this comment

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

Suggested change
PluginName = "NodeAffinityScoringPluginName"
NodeAffinityScoringPluginName = "NodeAffinityScoring"

)

// Plugins represents the plugins configuration.
type Plugins struct {
Copy link
Member

Choose a reason for hiding this comment

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

Can this stay in a separate file too?

}

// PluginBase is a common base for all plugins, requiring the Enabled field.
type PluginBase struct {
Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants