github.com/kubewharf/katalyst-core@v0.5.3/pkg/config/agent/dynamic/dynamic_base.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package dynamic
    18  
    19  import (
    20  	"sync"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/tmo"
    23  
    24  	"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/adminqos"
    25  	"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/auth"
    26  	"github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic/crd"
    27  )
    28  
    29  type DynamicAgentConfiguration struct {
    30  	mutex sync.RWMutex
    31  	conf  *Configuration
    32  }
    33  
    34  func NewDynamicAgentConfiguration() *DynamicAgentConfiguration {
    35  	return &DynamicAgentConfiguration{
    36  		conf: NewConfiguration(),
    37  	}
    38  }
    39  
    40  func (c *DynamicAgentConfiguration) GetDynamicConfiguration() *Configuration {
    41  	c.mutex.RLock()
    42  	defer c.mutex.RUnlock()
    43  
    44  	return c.conf
    45  }
    46  
    47  func (c *DynamicAgentConfiguration) SetDynamicConfiguration(conf *Configuration) {
    48  	c.mutex.Lock()
    49  	defer c.mutex.Unlock()
    50  
    51  	c.conf = conf
    52  }
    53  
    54  type Configuration struct {
    55  	*adminqos.AdminQoSConfiguration
    56  	*auth.AuthConfiguration
    57  	*tmo.TransparentMemoryOffloadingConfiguration
    58  }
    59  
    60  func NewConfiguration() *Configuration {
    61  	return &Configuration{
    62  		AdminQoSConfiguration:                    adminqos.NewAdminQoSConfiguration(),
    63  		AuthConfiguration:                        auth.NewAuthConfiguration(),
    64  		TransparentMemoryOffloadingConfiguration: tmo.NewTransparentMemoryOffloadingConfiguration(),
    65  	}
    66  }
    67  
    68  func (c *Configuration) ApplyConfiguration(conf *crd.DynamicConfigCRD) {
    69  	c.AdminQoSConfiguration.ApplyConfiguration(conf)
    70  	c.AuthConfiguration.ApplyConfiguration(conf)
    71  	c.TransparentMemoryOffloadingConfiguration.ApplyConfiguration(conf)
    72  }