Skip to content

Commit

Permalink
Refactor the operator logic
Browse files Browse the repository at this point in the history
According to discussion
Pause the machine config pool only when it neccessary

Split the reconcile loop to phases
Creation:
- add finalizer
- check if MCP exists, if no create it
- pause MCP, and wait for some time specified under the code
to give to machine-config controllers time to get the update
- if needed updated MCP, and all other resources
- after creation or update, wait again
- unpause MCP

Deletion:
- check if MCP exists
- if yes, pause the MCP and wait some time
- delete all components
- wait until all components will be deleted
- remove finalizer

All wait cycles implemenetd via requeue with `Result{Requeue: true, RequeueAfter: 10 * time.Second}`

Signed-off-by: Artyom Lukianov <[email protected]>
  • Loading branch information
Artyom Lukianov committed Jan 8, 2020
1 parent 306f0ba commit c3dd292
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kubeletconfig

import (
"encoding/json"
"time"

performancev1alpha1 "github.com/openshift-kni/performance-addon-operators/pkg/apis/performance/v1alpha1"
Expand All @@ -21,8 +22,8 @@ const (
topologyManagerPolicyBestEffort = "best-effort"
)

// NewPerformance returns new KubeletConfig object for performance sensetive workflows
func NewPerformance(profile *performancev1alpha1.PerformanceProfile) *machineconfigv1.KubeletConfig {
// New returns new KubeletConfig object for performance sensetive workflows
func New(profile *performancev1alpha1.PerformanceProfile) (*machineconfigv1.KubeletConfig, error) {
name := components.GetComponentName(profile.Name, components.RoleWorkerPerformance)
kubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{
CPUManagerPolicy: cpuManagerPolicyStatic,
Expand All @@ -42,6 +43,11 @@ func NewPerformance(profile *performancev1alpha1.PerformanceProfile) *machinecon
kubeletConfig.ReservedSystemCPUs = string(*profile.Spec.CPU.Reserved)
}

raw, err := json.Marshal(kubeletConfig)
if err != nil {
return nil, err
}

return &machineconfigv1.KubeletConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: machineconfigv1.GroupVersion.String(),
Expand All @@ -57,8 +63,8 @@ func NewPerformance(profile *performancev1alpha1.PerformanceProfile) *machinecon
},
},
KubeletConfig: &runtime.RawExtension{
Object: kubeletConfig,
Raw: raw,
},
},
}
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
var _ = Describe("Kubelet Config", func() {
It("should generate yaml with expected parameters", func() {
profile := testutils.NewPerformanceProfile("test")
kc := NewPerformance(profile)
kc, err := New(profile)
Expect(err).ToNot(HaveOccurred())

y, err := yaml.Marshal(kc)
Expect(err).ToNot(HaveOccurred())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ const (
environmentNonIsolatedCpus = "NON_ISOLATED_CPUS"
)

// NewPerformance returns new machine configuration object for performance sensetive workflows
func NewPerformance(assetsDir string, profile *performancev1alpha1.PerformanceProfile) (*machineconfigv1.MachineConfig, error) {
// New returns new machine configuration object for performance sensetive workflows
func New(assetsDir string, profile *performancev1alpha1.PerformanceProfile) (*machineconfigv1.MachineConfig, error) {
name := components.GetComponentName(profile.Name, components.RoleWorkerPerformance)
mc := &machineconfigv1.MachineConfig{
TypeMeta: metav1.TypeMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var _ = Describe("Machine Config", func() {
Count: 1024,
Size: "2M",
})
mc, err := NewPerformance(testAssetsDir, profile)
mc, err := New(testAssetsDir, profile)
Expect(err).ToNot(HaveOccurred())

y, err := yaml.Marshal(mc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NewPerformance returns new machine config pool for performance sensitive workflows
func NewPerformance(profile *performancev1alpha1.PerformanceProfile) *machineconfigv1.MachineConfigPool {
// New returns new machine config pool for performance sensitive workflows
func New(profile *performancev1alpha1.PerformanceProfile) *machineconfigv1.MachineConfigPool {
name := components.GetComponentName(profile.Name, components.RoleWorkerPerformance)
return &machineconfigv1.MachineConfigPool{
TypeMeta: metav1.TypeMeta{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var _ = Describe("Machine Config Pool", func() {
It("should generate yaml with expected parameters", func() {
profile := testutils.NewPerformanceProfile("test")
profile.Spec.NodeSelector = map[string]string{"test": "test"}
mcp := NewPerformance(profile)
mcp := New(profile)

y, err := yaml.Marshal(mcp)
Expect(err).ToNot(HaveOccurred())
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/performanceprofile/components/tuned/tuned.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ func NewWorkerRealTimeKernel(assetsDir string, profile *performancev1alpha1.Perf
sort.Strings(sortedKeys)

priority := uint64(30)
copyNodeSelector := map[string]string{}
for k, v := range profile.Spec.NodeSelector {
copyNodeSelector[k] = v
}
recommends := []tunedv1.TunedRecommend{
{
Profile: &name,
Priority: &priority,
Match: getProfileMatches(sortedKeys, profile.Spec.NodeSelector),
Match: getProfileMatches(sortedKeys, copyNodeSelector),
},
}
return new(name, profiles, recommends), nil
Expand Down
Loading

0 comments on commit c3dd292

Please sign in to comment.