@@ -30,7 +30,9 @@ import (
3030 "k8s.io/kubernetes/pkg/kubectl/scheme"
3131 "k8s.io/kubernetes/pkg/kubectl/util/templates"
3232
33+ operatorv1 "github.com/openshift/api/operator/v1"
3334 appsclient "github.com/openshift/client-go/apps/clientset/versioned"
35+ operatorclient "github.com/openshift/client-go/operator/clientset/versioned"
3436 unidlingapi "github.com/openshift/origin/pkg/unidling/api"
3537 utilunidling "github.com/openshift/origin/pkg/unidling/util"
3638)
@@ -65,6 +67,8 @@ type IdleOptions struct {
6567 ClientForMappingFn func (* meta.RESTMapping ) (resource.RESTClient , error )
6668 ClientConfig * rest.Config
6769 ClientSet kubernetes.Interface
70+ AppClient appsclient.Interface
71+ OperatorClient operatorclient.Interface
6872 ScaleClient scale.ScalesGetter
6973 Mapper meta.RESTMapper
7074
@@ -143,6 +147,16 @@ func (o *IdleOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []st
143147 return err
144148 }
145149
150+ o .AppClient , err = appsclient .NewForConfig (o .ClientConfig )
151+ if err != nil {
152+ return err
153+ }
154+
155+ o .OperatorClient , err = operatorclient .NewForConfig (o .ClientConfig )
156+ if err != nil {
157+ return err
158+ }
159+
146160 o .ClientForMappingFn = f .ClientForMapping
147161 o .Builder = f .NewBuilder
148162
@@ -545,6 +559,15 @@ type scaleInfo struct {
545559// scalable resources to zero, and annotating the associated endpoints objects with the scalable resources to unidle
546560// when they receive traffic.
547561func (o * IdleOptions ) RunIdle () error {
562+ clusterNetwork , err := o .OperatorClient .OperatorV1 ().Networks ().Get ("cluster" , metav1.GetOptions {})
563+ if err == nil {
564+ sdnType := clusterNetwork .Spec .DefaultNetwork .Type
565+
566+ if sdnType == operatorv1 .NetworkTypeOpenShiftSDN {
567+ fmt .Fprintln (o .ErrOut , "WARNING: idling when network policies are in place may cause connections to bypass network policy entirely" )
568+ }
569+ }
570+
548571 b := o .Builder ().
549572 WithScheme (scheme .Scheme , scheme .Scheme .PrioritizedVersionsAllGroups ()... ).
550573 ContinueOnError ().
@@ -589,12 +612,7 @@ func (o *IdleOptions) RunIdle() error {
589612 fmt .Fprintf (o .ErrOut , "warning: continuing on for valid scalable resources, but an error occurred while finding scalable resources to idle: %v" , err )
590613 }
591614
592- appClient , err := appsclient .NewForConfig (o .ClientConfig )
593- if err != nil {
594- return err
595- }
596-
597- scaleAnnotater := utilunidling .NewScaleAnnotater (o .ScaleClient , o .Mapper , appClient .AppsV1 (), o .ClientSet .CoreV1 (), func (currentReplicas int32 , annotations map [string ]string ) {
615+ scaleAnnotater := utilunidling .NewScaleAnnotater (o .ScaleClient , o .Mapper , o .AppClient .AppsV1 (), o .ClientSet .CoreV1 (), func (currentReplicas int32 , annotations map [string ]string ) {
598616 annotations [unidlingapi .IdledAtAnnotation ] = nowTime .UTC ().Format (time .RFC3339 )
599617 annotations [unidlingapi .PreviousScaleAnnotation ] = fmt .Sprintf ("%v" , currentReplicas )
600618 })
@@ -690,7 +708,7 @@ func (o *IdleOptions) RunIdle() error {
690708 for scaleRef , info := range toScale {
691709 if ! o .dryRun {
692710 info .scale .Spec .Replicas = 0
693- scaleUpdater := utilunidling .NewScaleUpdater (scheme .DefaultJSONEncoder (), info .namespace , appClient .AppsV1 (), o .ClientSet .CoreV1 ())
711+ scaleUpdater := utilunidling .NewScaleUpdater (scheme .DefaultJSONEncoder (), info .namespace , o . AppClient .AppsV1 (), o .ClientSet .CoreV1 ())
694712 if err := scaleAnnotater .UpdateObjectScale (scaleUpdater , info .namespace , scaleRef .CrossGroupObjectReference , info .obj , info .scale ); err != nil {
695713 fmt .Fprintf (o .ErrOut , "error: unable to scale %s %s/%s to 0, but still listed as target for unidling: %v\n " , scaleRef .Kind , info .namespace , scaleRef .Name , err )
696714 hadError = true
0 commit comments