github.com/lablabs/operator-sdk@v0.8.2/images/scorecard-proxy/cmd/proxy/main.go (about) 1 // Copyright 2019 The Operator-SDK Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import ( 18 "os" 19 20 proxy "github.com/operator-framework/operator-sdk/pkg/ansible/proxy" 21 "github.com/operator-framework/operator-sdk/pkg/ansible/proxy/controllermap" 22 "github.com/operator-framework/operator-sdk/pkg/k8sutil" 23 "github.com/operator-framework/operator-sdk/pkg/log/zap" 24 25 log "github.com/sirupsen/logrus" 26 "github.com/spf13/pflag" 27 "sigs.k8s.io/controller-runtime/pkg/client/config" 28 "sigs.k8s.io/controller-runtime/pkg/manager" 29 logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" 30 ) 31 32 func main() { 33 pflag.CommandLine.AddFlagSet(zap.FlagSet()) 34 pflag.Parse() 35 36 logf.SetLogger(zap.Logger()) 37 38 namespace, found := os.LookupEnv(k8sutil.WatchNamespaceEnvVar) 39 if found { 40 log.Infof("Watching %v namespace.", namespace) 41 } else { 42 log.Infof("%v environment variable not set. This operator is watching all namespaces.", 43 k8sutil.WatchNamespaceEnvVar) 44 } 45 46 mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{ 47 Namespace: namespace, 48 }) 49 if err != nil { 50 log.Fatal(err) 51 } 52 53 done := make(chan error) 54 cMap := controllermap.NewControllerMap() 55 56 // start the proxy 57 err = proxy.Run(done, proxy.Options{ 58 Address: "localhost", 59 Port: 8889, 60 KubeConfig: mgr.GetConfig(), 61 RESTMapper: mgr.GetRESTMapper(), 62 ControllerMap: cMap, 63 OwnerInjection: false, 64 LogRequests: true, 65 WatchedNamespaces: []string{namespace}, 66 DisableCache: true, 67 }) 68 if err != nil { 69 log.Fatalf("error starting proxy: %v", err) 70 } 71 72 // wait forever or exit on proxy crash/finish 73 err = <-done 74 if err == nil { 75 log.Info("Exiting") 76 } else { 77 log.Fatal(err.Error()) 78 } 79 }