Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inject proxy env. variable to CSI snapshot controller
- Loading branch information
Showing
14 changed files
with
959 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
pkg/operator/configobservation/configobservercontroller/config_observer_controller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package configobservercontroller | ||
|
||
import ( | ||
"github.com/openshift/library-go/pkg/operator/v1helpers" | ||
"k8s.io/client-go/tools/cache" | ||
|
||
cfginformers "github.com/openshift/client-go/config/informers/externalversions" | ||
"github.com/openshift/library-go/pkg/controller/factory" | ||
"github.com/openshift/library-go/pkg/operator/configobserver" | ||
"github.com/openshift/library-go/pkg/operator/configobserver/proxy" | ||
"github.com/openshift/library-go/pkg/operator/events" | ||
|
||
"github.com/openshift/cluster-csi-snapshot-controller-operator/pkg/operator/configobservation" | ||
"github.com/openshift/cluster-csi-snapshot-controller-operator/pkg/operator/configobservation/util" | ||
) | ||
|
||
// ConfigObserverController watches information that's relevant to CSI snapshot controller operatror and adds | ||
// it to CR.Spec.ObservedConfig. | ||
type ConfigObserverController struct { | ||
factory.Controller | ||
} | ||
|
||
// NewConfigObserverController returns a new ConfigObserverController. | ||
func NewConfigObserverController( | ||
operatorClient v1helpers.OperatorClient, | ||
configInformer cfginformers.SharedInformerFactory, | ||
eventRecorder events.Recorder, | ||
) *ConfigObserverController { | ||
informers := []factory.Informer{ | ||
operatorClient.Informer(), | ||
configInformer.Config().V1().Proxies().Informer(), | ||
} | ||
|
||
c := &ConfigObserverController{ | ||
Controller: configobserver.NewConfigObserver( | ||
operatorClient, | ||
eventRecorder.WithComponentSuffix("config-observer-controller-"), | ||
configobservation.Listers{ | ||
ProxyLister_: configInformer.Config().V1().Proxies().Lister(), | ||
PreRunCachesSynced: append([]cache.InformerSynced{}, | ||
operatorClient.Informer().HasSynced, | ||
configInformer.Config().V1().Proxies().Informer().HasSynced, | ||
), | ||
}, | ||
informers, | ||
proxy.NewProxyObserveFunc(util.ProxyConfigPath()), | ||
), | ||
} | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package configobservation | ||
|
||
import ( | ||
configlistersv1 "github.com/openshift/client-go/config/listers/config/v1" | ||
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
// Listers implement the configobserver.Listers interface. | ||
type Listers struct { | ||
ProxyLister_ configlistersv1.ProxyLister | ||
|
||
ResourceSync resourcesynccontroller.ResourceSyncer | ||
PreRunCachesSynced []cache.InformerSynced | ||
} | ||
|
||
func (l Listers) ProxyLister() configlistersv1.ProxyLister { | ||
return l.ProxyLister_ | ||
} | ||
|
||
func (l Listers) ResourceSyncer() resourcesynccontroller.ResourceSyncer { | ||
return l.ResourceSync | ||
} | ||
|
||
func (l Listers) PreRunHasSynced() []cache.InformerSynced { | ||
return l.PreRunCachesSynced | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package util | ||
|
||
import ( | ||
appsv1 "k8s.io/api/apps/v1" | ||
|
||
operatorapi "github.com/openshift/api/operator/v1" | ||
"github.com/openshift/library-go/pkg/operator/v1helpers" | ||
) | ||
|
||
// InjectObservedProxyInDeploymentContainers takes an observed proxy config and returns a patched Deployment with proxy env vars set. | ||
func InjectObservedProxyInDeploymentContainers(deployment *appsv1.Deployment, opSpec *operatorapi.OperatorSpec) (*appsv1.Deployment, error) { | ||
deploymentCopy := deployment.DeepCopy() | ||
containers, err := v1helpers.InjectObservedProxyIntoContainers( | ||
deploymentCopy.Spec.Template.Spec.Containers, | ||
opSpec.ObservedConfig.Raw, | ||
ProxyConfigPath()..., | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
deploymentCopy.Spec.Template.Spec.Containers = containers | ||
return deploymentCopy, nil | ||
} | ||
|
||
// ProxyConfigPath returns the path for the observed proxy config. This is a | ||
// function to avoid exposing a slice that could potentially be appended. | ||
func ProxyConfigPath() []string { | ||
return []string{"targetconfig", "proxy"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.