How to use Complete method of mgrconfig Package

Best Syzkaller code snippet using mgrconfig.Complete

mgr.go

Source:mgr.go Github

copy

Full Screen

1/*2Copyright 2016 The Rook Authors. All rights reserved.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13// Package mgr for the Ceph manager.14package mgr15import (16 "fmt"17 "path"18 "strconv"19 "strings"20 "sync"21 "github.com/coreos/pkg/capnslog"22 cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"23 rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"24 "github.com/rook/rook/pkg/clusterd"25 "github.com/rook/rook/pkg/daemon/ceph/client"26 cephconfig "github.com/rook/rook/pkg/daemon/ceph/config"27 "github.com/rook/rook/pkg/operator/ceph/cluster/mon"28 "github.com/rook/rook/pkg/operator/ceph/config"29 opspec "github.com/rook/rook/pkg/operator/ceph/spec"30 cephver "github.com/rook/rook/pkg/operator/ceph/version"31 "github.com/rook/rook/pkg/operator/k8sutil"32 v1 "k8s.io/api/core/v1"33 "k8s.io/apimachinery/pkg/api/errors"34 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"35)36var logger = capnslog.NewPackageLogger("github.com/rook/rook", "op-mgr")37var prometheusRuleName = "prometheus-ceph-vVERSION-rules"38const (39 // AppName is the ceph mgr application name40 AppName = "rook-ceph-mgr"41 serviceAccountName = "rook-ceph-mgr"42 prometheusModuleName = "prometheus"43 crashModuleName = "crash"44 pgautoscalerModuleName = "pg_autoscaler"45 metricsPort = 928346 monitoringPath = "/etc/ceph-monitoring/"47 serviceMonitorFile = "service-monitor.yaml"48 // minimum amount of memory in MB to run the pod49 cephMgrPodMinimumMemory uint64 = 51250)51// Cluster represents the Rook and environment configuration settings needed to set up Ceph mgrs.52type Cluster struct {53 clusterInfo *cephconfig.ClusterInfo54 Namespace string55 Replicas int56 placement rookalpha.Placement57 annotations rookalpha.Annotations58 context *clusterd.Context59 dataDir string60 Network cephv1.NetworkSpec61 resources v1.ResourceRequirements62 priorityClassName string63 ownerRef metav1.OwnerReference64 dashboard cephv1.DashboardSpec65 monitoringSpec cephv1.MonitoringSpec66 mgrSpec cephv1.MgrSpec67 cephVersion cephv1.CephVersionSpec68 rookVersion string69 exitCode func(err error) (int, bool)70 dataDirHostPath string71 isUpgrade bool72 skipUpgradeChecks bool73 appliedHttpBind bool74}75// New creates an instance of the mgr76func New(77 clusterInfo *cephconfig.ClusterInfo,78 context *clusterd.Context,79 namespace, rookVersion string,80 cephVersion cephv1.CephVersionSpec,81 placement rookalpha.Placement,82 annotations rookalpha.Annotations,83 network cephv1.NetworkSpec,84 dashboard cephv1.DashboardSpec,85 monitoringSpec cephv1.MonitoringSpec,86 mgrSpec cephv1.MgrSpec,87 resources v1.ResourceRequirements,88 priorityClassName string,89 ownerRef metav1.OwnerReference,90 dataDirHostPath string,91 isUpgrade bool,92 skipUpgradeChecks bool,93) *Cluster {94 return &Cluster{95 clusterInfo: clusterInfo,96 context: context,97 Namespace: namespace,98 placement: placement,99 annotations: annotations,100 rookVersion: rookVersion,101 cephVersion: cephVersion,102 Replicas: 1,103 dataDir: k8sutil.DataDir,104 dashboard: dashboard,105 monitoringSpec: monitoringSpec,106 mgrSpec: mgrSpec,107 Network: network,108 resources: resources,109 priorityClassName: priorityClassName,110 ownerRef: ownerRef,111 exitCode: getExitCode,112 dataDirHostPath: dataDirHostPath,113 isUpgrade: isUpgrade,114 skipUpgradeChecks: skipUpgradeChecks,115 }116}117var updateDeploymentAndWait = mon.UpdateCephDeploymentAndWait118func (c *Cluster) getDaemonIDs() []string {119 var daemonIDs []string120 for i := 0; i < c.Replicas; i++ {121 if i >= 2 {122 logger.Errorf("cannot have more than 2 mgrs")123 break124 }125 daemonIDs = append(daemonIDs, k8sutil.IndexToName(i))126 }127 return daemonIDs128}129// Start begins the process of running a cluster of Ceph mgrs.130func (c *Cluster) Start() error {131 // Validate pod's memory if specified132 err := opspec.CheckPodMemory(c.resources, cephMgrPodMinimumMemory)133 if err != nil {134 return fmt.Errorf("%v", err)135 }136 logger.Infof("start running mgr")137 daemonIDs := c.getDaemonIDs()138 for _, daemonID := range daemonIDs {139 resourceName := fmt.Sprintf("%s-%s", AppName, daemonID)140 mgrConfig := &mgrConfig{141 DaemonID: daemonID,142 ResourceName: resourceName,143 DataPathMap: config.NewStatelessDaemonDataPathMap(config.MgrType, daemonID, c.Namespace, c.dataDirHostPath),144 }145 // generate keyring specific to this mgr daemon saved to k8s secret146 keyring, err := c.generateKeyring(mgrConfig)147 if err != nil {148 return fmt.Errorf("failed to generate keyring for %q. %+v", resourceName, err)149 }150 // start the deployment151 d := c.makeDeployment(mgrConfig)152 logger.Debugf("starting mgr deployment: %+v", d)153 _, err = c.context.Clientset.AppsV1().Deployments(c.Namespace).Create(d)154 if err != nil {155 if !errors.IsAlreadyExists(err) {156 return fmt.Errorf("failed to create mgr deployment %s. %+v", resourceName, err)157 }158 logger.Infof("deployment for mgr %s already exists. updating if needed", resourceName)159 // Always invoke ceph version before an upgrade so we are sure to be up-to-date160 daemon := string(config.MgrType)161 var cephVersionToUse cephver.CephVersion162 // If this is not a Ceph upgrade there is no need to check the ceph version163 if c.isUpgrade {164 currentCephVersion, err := client.LeastUptodateDaemonVersion(c.context, c.clusterInfo.Name, daemon)165 if err != nil {166 logger.Warningf("failed to retrieve current ceph %s version. %+v", daemon, err)167 logger.Debug("could not detect ceph version during update, this is likely an initial bootstrap, proceeding with c.clusterInfo.CephVersion")168 cephVersionToUse = c.clusterInfo.CephVersion169 } else {170 logger.Debugf("current cluster version for mgrs before upgrading is: %+v", currentCephVersion)171 cephVersionToUse = currentCephVersion172 }173 }174 if err := updateDeploymentAndWait(c.context, d, c.Namespace, daemon, mgrConfig.DaemonID, cephVersionToUse, c.isUpgrade, c.skipUpgradeChecks); err != nil {175 return fmt.Errorf("failed to update mgr deployment %s. %+v", resourceName, err)176 }177 }178 if existingDeployment, err := c.context.Clientset.AppsV1().Deployments(c.Namespace).Get(d.GetName(), metav1.GetOptions{}); err != nil {179 logger.Warningf("failed to find mgr deployment %s for keyring association: %+v", resourceName, err)180 } else {181 if err = c.associateKeyring(keyring, existingDeployment); err != nil {182 logger.Warningf("failed to associate keyring with mgr deployment %s: %+v", resourceName, err)183 }184 }185 }186 if err := c.configureDashboardService(); err != nil {187 logger.Errorf("failed to enable dashboard. %+v", err)188 }189 // configure the mgr modules190 c.configureModules(daemonIDs)191 // create the metrics service192 service := c.makeMetricsService(AppName)193 if _, err := c.context.Clientset.CoreV1().Services(c.Namespace).Create(service); err != nil {194 if !errors.IsAlreadyExists(err) {195 return fmt.Errorf("failed to create mgr service. %+v", err)196 }197 logger.Infof("mgr metrics service already exists")198 } else {199 logger.Infof("mgr metrics service started")200 }201 // enable monitoring if `monitoring: enabled: true`202 if c.monitoringSpec.Enabled {203 if c.clusterInfo.CephVersion.IsAtLeastNautilus() {204 logger.Infof("starting monitoring deployment")205 // servicemonitor takes some metadata from the service for easy mapping206 if err := c.enableServiceMonitor(service); err != nil {207 logger.Errorf("failed to enable service monitor. %+v", err)208 } else {209 logger.Infof("servicemonitor enabled")210 }211 // namespace in which the prometheusRule should be deployed212 // if left empty, it will be deployed in current namespace213 namespace := c.monitoringSpec.RulesNamespace214 if namespace == "" {215 namespace = c.Namespace216 }217 if err := c.deployPrometheusRule(prometheusRuleName, namespace); err != nil {218 logger.Errorf("failed to deploy prometheus rule. %+v", err)219 } else {220 logger.Infof("prometheusRule deployed")221 }222 logger.Debugf("ended monitoring deployment")223 } else {224 logger.Debugf("monitoring not supported for ceph versions <v%v", c.clusterInfo.CephVersion.Major)225 }226 }227 return nil228}229func (c *Cluster) configureModules(daemonIDs []string) {230 // Configure the modules asynchronously so we can complete all the configuration much sooner.231 var wg sync.WaitGroup232 if !c.needHTTPBindFix() {233 startModuleConfiguration(&wg, "http bind settings", c.clearHTTPBindFix)234 }235 startModuleConfiguration(&wg, "orchestrator modules", c.configureOrchestratorModules)236 startModuleConfiguration(&wg, "prometheus", c.enablePrometheusModule)237 startModuleConfiguration(&wg, "crash", c.enableCrashModule)238 startModuleConfiguration(&wg, "mgr module(s) from the spec", c.configureMgrModules)239 startModuleConfiguration(&wg, "dashboard", c.configureDashboardModules)240 // Wait for the goroutines to complete before continuing241 wg.Wait()242}243func startModuleConfiguration(wg *sync.WaitGroup, description string, configureModules func() error) {244 wg.Add(1)245 go func() {246 err := configureModules()247 if err != nil {248 logger.Errorf("failed modules: %s. %+v", description, err)249 } else {250 logger.Infof("successful modules: %s", description)251 }252 wg.Done()253 }()254}255// Ceph docs about the prometheus module: http://docs.ceph.com/docs/master/mgr/prometheus/256func (c *Cluster) enablePrometheusModule() error {257 if err := client.MgrEnableModule(c.context, c.Namespace, prometheusModuleName, true); err != nil {258 return fmt.Errorf("failed to enable mgr prometheus module. %+v", err)259 }260 return nil261}262// Ceph docs about the crash module: https://docs.ceph.com/docs/master/mgr/crash/263func (c *Cluster) enableCrashModule() error {264 if err := client.MgrEnableModule(c.context, c.Namespace, crashModuleName, true); err != nil {265 return fmt.Errorf("failed to enable mgr crash module. %+v", err)266 }267 return nil268}269func (c *Cluster) configureMgrModules() error {270 // Enable mgr modules from the spec271 for _, module := range c.mgrSpec.Modules {272 if module.Name == "" {273 return fmt.Errorf("name not specified for the mgr module configuration")274 }275 if wellKnownModule(module.Name) {276 return fmt.Errorf("cannot configure mgr module %s that is configured with other cluster settings", module.Name)277 }278 minVersion, versionOK := c.moduleMeetsMinVersion(module.Name)279 if !versionOK {280 return fmt.Errorf("module %s cannot be configured because it requires at least Ceph version %v", module.Name, minVersion)281 }282 if module.Enabled {283 if err := client.MgrEnableModule(c.context, c.Namespace, module.Name, false); err != nil {284 return fmt.Errorf("failed to enable mgr module %s. %+v", module.Name, err)285 }286 // Configure special settings for individual modules that are enabled287 if module.Name == pgautoscalerModuleName && c.clusterInfo.CephVersion.IsAtLeastNautilus() {288 monStore := config.GetMonStore(c.context, c.Namespace)289 // Ceph Octopus will have that option enabled290 err := monStore.Set("global", "osd_pool_default_pg_autoscale_mode", "on")291 if err != nil {292 return fmt.Errorf("failed to enable pg autoscale mode for newly created pools. %+v", err)293 }294 err = monStore.Set("global", "mon_pg_warn_min_per_osd", "0")295 if err != nil {296 return fmt.Errorf("failed to set minimal number PGs per (in) osd before we warn the admin to 0. %+v", err)297 }298 }299 } else {300 if err := client.MgrDisableModule(c.context, c.Namespace, module.Name); err != nil {301 return fmt.Errorf("failed to disable mgr module %s. %+v", module.Name, err)302 }303 }304 }305 return nil306}307func (c *Cluster) moduleMeetsMinVersion(name string) (*cephver.CephVersion, bool) {308 minVersions := map[string]cephver.CephVersion{309 // The PG autoscaler module requires Nautilus310 pgautoscalerModuleName: {Major: 14},311 }312 if ver, ok := minVersions[name]; ok {313 // Check if the required min version is met314 return &ver, c.clusterInfo.CephVersion.IsAtLeast(ver)315 }316 // no min version was required317 return nil, true318}319func wellKnownModule(name string) bool {320 knownModules := []string{rookModuleName, dashboardModuleName, prometheusModuleName, crashModuleName}321 for _, known := range knownModules {322 if name == known {323 return true324 }325 }326 return false327}328// add a servicemonitor that allows prometheus to scrape from the monitoring endpoint of the cluster329func (c *Cluster) enableServiceMonitor(service *v1.Service) error {330 name := service.GetName()331 namespace := service.GetNamespace()332 serviceMonitor, err := k8sutil.GetServiceMonitor(path.Join(monitoringPath, serviceMonitorFile))333 if err != nil {334 return fmt.Errorf("service monitor could not be enabled. %+v", err)335 }336 serviceMonitor.SetName(name)337 serviceMonitor.SetNamespace(namespace)338 k8sutil.SetOwnerRef(&serviceMonitor.ObjectMeta, &c.ownerRef)339 serviceMonitor.Spec.NamespaceSelector.MatchNames = []string{namespace}340 serviceMonitor.Spec.Selector.MatchLabels = service.GetLabels()341 if _, err := k8sutil.CreateOrUpdateServiceMonitor(serviceMonitor); err != nil {342 return fmt.Errorf("service monitor could not be enabled. %+v", err)343 }344 return nil345}346// deploy prometheusRule that adds alerting and/or recording rules to the cluster347func (c *Cluster) deployPrometheusRule(name, namespace string) error {348 version := strconv.Itoa(c.clusterInfo.CephVersion.Major)349 name = strings.Replace(name, "VERSION", version, 1)350 prometheusRuleFile := name + ".yaml"351 prometheusRuleFile = path.Join(monitoringPath, prometheusRuleFile)352 prometheusRule, err := k8sutil.GetPrometheusRule(prometheusRuleFile)353 if err != nil {354 return fmt.Errorf("prometheus rule could not be deployed. %+v", err)355 }356 prometheusRule.SetName(name)357 prometheusRule.SetNamespace(namespace)358 owners := append(prometheusRule.GetOwnerReferences(), c.ownerRef)359 k8sutil.SetOwnerRefs(&prometheusRule.ObjectMeta, owners)360 if _, err := k8sutil.CreateOrUpdatePrometheusRule(prometheusRule); err != nil {361 return fmt.Errorf("prometheus rule could not be deployed. %+v", err)362 }363 return nil364}...

Full Screen

Full Screen

mgr_grpc.go

Source:mgr_grpc.go Github

copy

Full Screen

...76 _ = value.(rpcpb.EdgeDevice_SyncServer).Send(&aranyagopb.Cmd{77 Kind: aranyagopb.CMD_REJECT,78 Sid: 0,79 Seq: 0,80 Complete: true,81 Payload: data,82 })83 return true84 })85 })86}87func (m *GRPCManager) Sync(server rpcpb.EdgeDevice_SyncServer) error {88 connCtx, closeConn := context.WithCancel(server.Context())89 defer closeConn()90 allMsgCh := make(chan *aranyagopb.Msg, 16)91 go func() {92 for {93 msg, err := server.Recv()94 if err != nil {...

Full Screen

Full Screen

symbolize.go

Source:symbolize.go Github

copy

Full Screen

...29 TargetVMArch: *flagArch,30 KernelObj: *flagKernelObj,31 KernelSrc: *flagKernelSrc,32 }33 cfg.CompleteKernelDirs()34 reporter, err := report.NewReporter(cfg)35 if err != nil {36 fmt.Fprintf(os.Stderr, "failed to create reporter: %v\n", err)37 os.Exit(1)38 }39 text, err := ioutil.ReadFile(flag.Args()[0])40 if err != nil {41 fmt.Fprintf(os.Stderr, "failed to open input file: %v\n", err)42 os.Exit(1)43 }44 rep := reporter.Parse(text)45 if rep == nil {46 rep = &report.Report{Report: text}47 }...

Full Screen

Full Screen

Complete

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mgrconfig, err := config.NewConfig("ini", "config.ini")4 if err != nil {5 fmt.Println("error:", err)6 }7 fmt.Println(mgrconfig.String("mysql::user"))8 fmt.Println(mgrconfig.String("mysql::password"))9 fmt.Println(mgrconfig.String("mysql::host"))10 fmt.Println(mgrconfig.String("mysql::port"))11 fmt.Println(mgrconfig.String("mysql::database"))12}

Full Screen

Full Screen

Complete

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var args struct {4 }5 p := argparse.NewParser("prog", "description")6 p.AddArgument("-v", "--verbose", &args.Verbose, "verbose mode")7 p.AddArgument("count", &args.Count, argparse.Options{Required: true})8 p.AddArgument("thing", &args.Thing, argparse.Options{Required: false})9 err := p.Parse(nil)10 if err != nil {11 fmt.Println(err)12 }13 fmt.Println(args)14}15import (16func main() {17 var args struct {18 }19 p := argparse.NewParser("prog", "description")20 p.AddArgument("-v", "--verbose", &args.Verbose, "verbose mode")21 p.AddArgument("count", &args.Count, argparse.Options{Required: true})22 p.AddArgument("thing", &args.Thing, argparse.Options{Required: false})23 err := p.Parse(nil)24 if err != nil {25 fmt.Println(err)26 }27 fmt.Println(args)28}29import (30func main() {31 var args struct {32 }33 p := argparse.NewParser("prog", "description")

Full Screen

Full Screen

Complete

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 mgr := mgrconfig.NewManager()4 mgr.Add("a", "b")5 mgr.Add("a", "c")6 mgr.Add("a", "d")7 mgr.Add("b", "e")8 mgr.Add("b", "f")9 mgr.Add("c", "g")10 mgr.Add("c", "h")11 mgr.Add("d", "i")12 mgr.Add("d", "j")13 mgr.Add("e", "k")14 mgr.Add("e", "l")15 mgr.Add("f", "m")16 mgr.Add("f", "n")17 mgr.Add("g", "o")18 mgr.Add("g", "p")19 mgr.Add("h", "q")20 mgr.Add("h", "r")21 mgr.Add("i", "s")22 mgr.Add("i", "t")23 mgr.Add("j", "u")24 mgr.Add("j", "v")25 mgr.Add("k", "w")26 mgr.Add("k", "x")27 mgr.Add("l", "y")28 mgr.Add("l", "z")29 mgr.Add("m", "A")30 mgr.Add("m", "B")31 mgr.Add("n", "C")32 mgr.Add("n", "D")33 mgr.Add("o", "E")34 mgr.Add("o", "F")35 mgr.Add("p", "G")36 mgr.Add("p", "H")37 mgr.Add("q", "I")38 mgr.Add("q", "J")39 mgr.Add("r", "K")40 mgr.Add("r", "L")41 mgr.Add("s", "M")42 mgr.Add("s", "N")43 mgr.Add("t", "O")44 mgr.Add("t", "P")45 mgr.Add("u", "Q")46 mgr.Add("u", "R")47 mgr.Add("v", "S")48 mgr.Add("v", "T")49 mgr.Add("w", "U")50 mgr.Add("w", "V")51 mgr.Add("x", "W")52 mgr.Add("x", "X")53 mgr.Add("y", "Y")54 mgr.Add("y", "Z")55 mgr.Add("z", "

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful