id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c3900
for { select { case <-callbacks.Dying(): return nil case <-watcher.Changes(): // ensure namespace has been deleted - notfound error expected. _, err := k.GetNamespace(k.namespace) if errors.IsNotFound(err) { // namespace ha been deleted. return nil } if err != nil { return errors.Trace(err) } logger.Debugf("namespace %q is still been terminating", k.namespace) } } }
c3901
querying API version", string(body)) } version := info.GitVersion // git version is "vX.Y.Z", strip the "v" version = strings.Trim(version, "v") return version, nil }
c3902
Namespace: k.namespace, Labels: map[string]string{labelApplication: appName}, Annotations: annotations.ToMap()}, Type: core.SecretTypeDockerConfigJson, Data: map[string][]byte{ core.DockerConfigJsonKey: secretData, }, } return errors.Trace(k.ensureSecret(newSecret)) }
c3903
:= k.client().CoreV1().Secrets(k.namespace).Update(sec) return errors.Trace(err) }
c3904
true}) if err != nil { if k8serrors.IsNotFound(err) { return nil, errors.NotFoundf("secret %q", secretName) } return nil, errors.Trace(err) } return secret, nil }
c3905
:= k.client().CoreV1().Secrets(k.namespace).Create(secret) return errors.Trace(err) }
c3906
err := secrets.Delete(secretName, &v1.DeleteOptions{ PropagationPolicy: &defaultPropagationPolicy, }) if k8serrors.IsNotFound(err) { return nil } return errors.Trace(err) }
c3907
v1.GetOptions{IncludeUninitialized: true}) if k8serrors.IsNotFound(err) { return result, nil } if err != nil { return result, errors.Trace(err) } result.Exists = true result.Terminating = operator.DeletionTimestamp != nil return result, nil }
c3908
} if sc.Provisioner != cfg.storageProvisioner { return errors.NewNotValid( nil, fmt.Sprintf("storage class %q has provisoner %q, not %q", cfg.storageClass, sc.Provisioner, cfg.storageProvisioner)) } return nil }
c3909
err == nil { haveStorageClass = true storageClassName = sc.Name } } if !haveStorageClass { return nil, errors.NewNotFound(nil, fmt.Sprintf( "cannot create persistent volume as storage class %q cannot be found", storageClassName)) } accessMode := params.accessMode if accessMode == "" { accessMode = core.ReadWriteOnce } return &core.PersistentVolumeClaimSpec{ StorageClassName: &storageClassName, Resources: core.ResourceRequirements{ Requests: core.ResourceList{ core.ResourceStorage: params.requestedVolumeSize, }, }, AccessModes: []core.PersistentVolumeAccessMode{accessMode}, }, nil }
c3910
sc, err := storageClasses.Get(qualifiedName, v1.GetOptions{}) if err == nil { return sc, nil } if !k8serrors.IsNotFound(err) { return nil, errors.Trace(err) } return storageClasses.Get(name, v1.GetOptions{}) }
c3911
but no storage provisioner has been specified", cfg.Name)) } // Create the storage class with the specified provisioner. var reclaimPolicy *core.PersistentVolumeReclaimPolicy if cfg.ReclaimPolicy != "" { policy := core.PersistentVolumeReclaimPolicy(cfg.ReclaimPolicy) reclaimPolicy = &policy } storageClasses := k.client().StorageV1().StorageClasses() sc = &k8sstorage.StorageClass{ ObjectMeta: v1.ObjectMeta{ Name: qualifiedStorageClassName(cfg.Namespace, cfg.Name), }, Provisioner: cfg.Provisioner, ReclaimPolicy: reclaimPolicy, Parameters: cfg.Parameters, } if cfg.Namespace != "" { sc.Labels = map[string]string{labelModel: k.namespace} } _, err = storageClasses.Create(sc) if err != nil { return nil, errors.Annotatef(err, "creating storage class %q", cfg.Name) } return &caas.StorageProvisioner{ Name: sc.Name, Provisioner: sc.Provisioner, Parameters: sc.Parameters, }, nil }
c3912
for _, c := range p.Spec.Containers { secretName := appSecretName(deploymentName, c.Name) if err := k.deleteSecret(secretName); err != nil { return errors.Annotatef(err, "deleting %s secret for container %s", appName, c.Name) } } // Delete operator storage volumes. volumeNames, err := k.deleteVolumeClaims(appName, &p) if err != nil { return errors.Trace(err) } // Just in case the volume reclaim policy is retain, we force deletion // for operators as the volume is an inseparable part of the operator. for _, volName := range volumeNames { err = pvs.Delete(volName, &v1.DeleteOptions{ PropagationPolicy: &defaultPropagationPolicy, }) if err != nil && !k8serrors.IsNotFound(err) { return errors.Annotatef(err, "deleting operator persistent volume %v for %v", volName, appName) } } } return errors.Trace(k.deleteDeployment(operatorName)) }
c3913
Message: message, } return &result, nil } if !k8serrors.IsNotFound(err) { return nil, errors.Trace(err) } deployments := k.client().AppsV1().Deployments(k.namespace) deployment, err := deployments.Get(deploymentName, v1.GetOptions{}) if err != nil && !k8serrors.IsNotFound(err) { return nil, errors.Trace(err) } if err == nil { if deployment.Spec.Replicas != nil { scale := int(*deployment.Spec.Replicas) result.Scale = &scale } message, ssStatus, err := k.getDeploymentStatus(deployment) if err != nil { return nil, errors.Annotatef(err, "getting status for %s", ss.Name) } result.Status = status.StatusInfo{ Status: ssStatus, Message: message, } } return &result, nil }
c3914
return errors.Trace(err) } if err := k.deleteDeployment(deploymentName); err != nil { return errors.Trace(err) } secrets := k.client().CoreV1().Secrets(k.namespace) secretList, err := secrets.List(v1.ListOptions{ LabelSelector: applicationSelector(appName), }) if err != nil { return errors.Trace(err) } for _, s := range secretList.Items { if err := k.deleteSecret(s.Name); err != nil { return errors.Trace(err) } } return nil }
c3915
k.ensureCustomResourceDefinitionTemplate(name, crd) if err != nil { return errors.Annotate(err, fmt.Sprintf("ensure custom resource definition %q", name)) } logger.Debugf("ensured custom resource definition %q", crd.ObjectMeta.Name) } return nil }
c3916
errors.NotSupportedf("upgrading %v", appName) } for i, c := range existingStatefulSet.Spec.Template.Spec.Containers { if !podcfg.IsJujuOCIImage(c.Image) { continue } tagSep := strings.LastIndex(c.Image, ":") c.Image = fmt.Sprintf("%s:%s", c.Image[:tagSep], vers.String()) existingStatefulSet.Spec.Template.Spec.Containers[i] = c } _, err = statefulsets.Update(existingStatefulSet) return errors.Trace(err) }
c3917
:= k.client().AppsV1().StatefulSets(k.namespace).Create(spec) return errors.Trace(err) }
c3918
err := deployments.Delete(name, &v1.DeleteOptions{ PropagationPolicy: &defaultPropagationPolicy, }) if k8serrors.IsNotFound(err) { return nil } return errors.Trace(err) }
c3919
true}) if err == nil { spec.Spec.ClusterIP = existing.Spec.ClusterIP spec.ObjectMeta.ResourceVersion = existing.ObjectMeta.ResourceVersion } _, err = services.Update(spec) if k8serrors.IsNotFound(err) { _, err = services.Create(spec) } return errors.Trace(err) }
c3920
err := services.Delete(deploymentName, &v1.DeleteOptions{ PropagationPolicy: &defaultPropagationPolicy, }) if k8serrors.IsNotFound(err) { return nil } return errors.Trace(err) }
c3921
Labels: resourceTags, Annotations: map[string]string{ "ingress.kubernetes.io/rewrite-target": "", "ingress.kubernetes.io/ssl-redirect": strconv.FormatBool(ingressSSLRedirect), "kubernetes.io/ingress.class": ingressClass, "kubernetes.io/ingress.allow-http": strconv.FormatBool(ingressAllowHTTP), "ingress.kubernetes.io/ssl-passthrough": strconv.FormatBool(ingressSSLPassthrough), }, }, Spec: v1beta1.IngressSpec{ Rules: []v1beta1.IngressRule{{ Host: host, IngressRuleValue: v1beta1.IngressRuleValue{ HTTP: &v1beta1.HTTPIngressRuleValue{ Paths: []v1beta1.HTTPIngressPath{{ Path: httpPath, Backend: v1beta1.IngressBackend{ ServiceName: svc.Name, ServicePort: svc.Spec.Ports[0].TargetPort}, }}}, }}}, }, } return k.ensureIngress(spec) }
c3922
resource for %s", appName) return k.deleteIngress(appName) }
c3923
err := k.client().CoreV1().Pods(k.namespace).Watch(v1.ListOptions{ LabelSelector: selector, Watch: true, IncludeUninitialized: true, }) if err != nil { return nil, errors.Trace(err) } return k.newWatcher(w, appName, k.clock) }
c3924
if err != nil { return nil, errors.Trace(err) } deployments := k.client().AppsV1().Deployments(k.namespace) dwatcher, err := deployments.Watch(v1.ListOptions{ LabelSelector: applicationSelector(appName), Watch: true, }) if err != nil { return nil, errors.Trace(err) } w2, err := k.newWatcher(dwatcher, appName, k.clock) if err != nil { return nil, errors.Trace(err) } return watcher.NewMultiNotifyWatcher(w1, w2), nil }
c3925
true, }) if err != nil { return nil, errors.Trace(err) } return k.newWatcher(w, appName, k.clock) }
c3926
{ return nil, errors.NotFoundf("operator pod for application %q", appName) } opPod := podsList.Items[0] terminated := opPod.DeletionTimestamp != nil now := time.Now() statusMessage, opStatus, since, err := k.getPODStatus(opPod, now) return &caas.Operator{ Id: string(opPod.UID), Dying: terminated, Status: status.StatusInfo{ Status: opStatus, Message: statusMessage, Since: &since, }, }, nil }
c3927
_, err := configMaps.Update(configMap) if k8serrors.IsNotFound(err) { _, err = configMaps.Create(configMap) } return errors.Trace(err) }
c3928
&defaultPropagationPolicy, }) if k8serrors.IsNotFound(err) { return nil } return errors.Trace(err) }
c3929
:= k.client().CoreV1().ConfigMaps(k.namespace).Create(configMap) return errors.Trace(err) }
c3930
true}) if err != nil { if k8serrors.IsNotFound(err) { return nil, errors.NotFoundf("configmap %q", cmName) } return nil, errors.Trace(err) } return cm, nil }
c3931
:= statefulsets.Get(legacyName, v1.GetOptions{IncludeUninitialized: true}) return err == nil }
c3932
return nil, nil, errors.Trace(err) } return model, func() { ph.Release() }, nil }
c3933
store, } c.removeCloudAPIFunc = c.cloudAPI return modelcmd.WrapBase(c) }
c3934
return &oracleVolumeSource{ env: env, envName: name, modelUUID: uuid, api: api, clock: clock, }, nil }
c3935
{ return s.api.ComposeName(s.env.namespace.Value(s.envName + "-" + tag)) }
c3936
vol, err := s.createVolume(volume) if err != nil { results[i].Error = errors.Trace(err) continue } results[i].Volume = vol } return results, nil }
c3937
return false, errors.Errorf("volume entered error state: %q", details.Status_detail) } return string(details.Status) == desiredStatus, nil }
c3938
return false, errors.Trace(err) } return string(details.State) == desiredStatus, nil }
c3939
> 1 { return existing[0] - 1, nil } diff := existing[i+1] - existing[i] if diff > 1 { return existing[i] + 1, nil } } return 0, errors.Errorf("no free index") }
c3940
func(tag names.ModelTag) (state.NotifyWatcher, error), getAuthFunc common.GetAuthFunc, ) CloudSpecAPI { return cloudSpecAPI{resources, getCloudSpec, watchCloudSpec, getAuthFunc} }
c3941
if err != nil { results.Results[i].Error = common.ServerError(err) continue } if !authFunc(tag) { results.Results[i].Error = common.ServerError(common.ErrPerm) continue } results.Results[i] = s.GetCloudSpec(tag) } return results, nil }
c3942
spec.Type, Name: spec.Name, Region: spec.Region, Endpoint: spec.Endpoint, IdentityEndpoint: spec.IdentityEndpoint, StorageEndpoint: spec.StorageEndpoint, Credential: paramsCloudCredential, CACertificates: spec.CACertificates, } return result }
c3943
if !authFunc(tag) { results.Results[i].Error = common.ServerError(common.ErrPerm) continue } w, err := s.watchCloudSpecChanges(tag) if err == nil { results.Results[i] = w } else { results.Results[i].Error = common.ServerError(err) } } return results, nil }
c3944
ok { // Executable could not be found, go 1.2 if os.IsNotExist(execErr.Err) || execErr.Err == exec.ErrNotFound { return true } } return false }
c3945
val := range c { result[attr] = val } return result }
c3946
if err != nil { return nil, errors.Trace(err) } return facade, nil }
c3947
return nil, errors.Trace(err) } return worker, nil }
c3948
{ w := &simpleWorker{} w.tomb.Go(func() error { return doWork(w.tomb.Dying()) }) return w }
c3949
&UnregisterCmd{hookContextFunc: componentHookContext(ctx)}, nil }
c3950
return errors.Trace(err) } // TODO(ericsnow) Is the flush really necessary? // We flush to state immediately so that status reflects the // payload correctly. if err := hctx.Flush(); err != nil { return errors.Trace(err) } return nil }
c3951
cfg.Engine, StatePool: cfg.StatePoolReporter, PubSub: cfg.PubSubReporter, MachineLock: cfg.MachineLock, PrometheusGatherer: cfg.PrometheusGatherer, Presence: cfg.PresenceRecorder, }) if err != nil { return errors.Trace(err) } go func() { cfg.Engine.Wait() logger.Debugf("engine stopped, stopping introspection") w.Kill() w.Wait() logger.Debugf("introspection stopped") }() return nil }
c3952
!= nil { return nil, errors.Trace(err) } if err := r.Register(prometheus.NewProcessCollector( prometheus.ProcessCollectorOpts{})); err != nil { return nil, errors.Trace(err) } return r, nil }
c3953
non-mask bits set), which is the broadcast // address for the subnet. n := ipUint32(subnet.IP) for i := reservedAddressRangeEnd + 1; i < (1<<uint64(bits-ones) - 1); i++ { ip := uint32IP(n + uint32(i)) if !ip.IsGlobalUnicast() { continue } index := ipIndex(ip, subnetMaskUint32) if inUse.Bit(index) == 0 { return ip, nil } } return nil, errors.Errorf("no addresses available in %s", subnet) }
c3954
if !ip.IsGlobalUnicast() { continue } if n == valid { return ip } valid++ } return nil }
c3955
forward config change: %v", err) return currentSender, nil } // Shutdown the existing sink since we need to now create a new one. if err := closeExisting(); err != nil { return nil, errors.Trace(err) } sink, err := OpenTrackingSink(TrackingSinkArgs{ Name: lf.args.Name, Config: cfg, Caller: lf.args.Caller, OpenSink: lf.args.OpenSink, }) if err != nil { return nil, errors.Trace(err) } lf.enabledCh <- true return sink, nil }
c3956
if !lf.enabled && enabled { logger.Infof("log forward enabled, starting to stream logs to syslog sink") } lf.enabled = enabled return enabled, nil }
c3957
return errors.Trace(lf.loop()) }, }) if err != nil { return nil, errors.Trace(err) } return lf, nil }
c3958
} return errors.Trace(err) } if err = m.processMachineProfileChanges(info); err != nil && errors.IsNotValid(err) { // Return to stop mutating the machine, but no need to restart // the worker. return nil } else if err != nil { return errors.Trace(err) } case <-removed: if err := m.machineApi.Refresh(); err != nil { return errors.Trace(err) } if m.machineApi.Life() == params.Dead { return nil } } } }
c3959
hub := ctx.Hub() return NewControllerAPI( st, pool, authorizer, resources, presence, hub, ) }
c3960
return nil, errors.Trace(err) } return &ControllerAPIv6{v7}, nil }
c3961
return nil, errors.Trace(err) } return &ControllerAPIv5{v6}, nil }
c3962
return nil, errors.Trace(err) } return &ControllerAPIv4{v5}, nil }
c3963
return nil, errors.Trace(err) } return &ControllerAPIv3{v4}, nil }
c3964
authorizer, apiUser, ), CloudSpecAPI: cloudspec.NewCloudSpec( resources, cloudspec.MakeCloudSpecGetter(pool), cloudspec.MakeCloudSpecWatcherForModel(st), common.AuthFuncForTag(model.ModelTag()), ), state: st, statePool: pool, authorizer: authorizer, apiUser: apiUser, resources: resources, presence: presence, hub: hub, }, nil }
c3965
err != nil { return result, errors.Trace(err) } result.Result = version return result, nil }
c3966
{ types = []string{block.Type().String()} } else { types = append(types, block.Type().String()) } modelBlocks[uuid] = types } for uuid, blocks := range modelBlocks { model, ph, err := c.statePool.GetModel(uuid) if err != nil { logger.Debugf("unable to retrieve model %s: %v", uuid, err) continue } results.Models = append(results.Models, params.ModelBlockInfo{ UUID: model.UUID(), Name: model.Name(), OwnerTag: model.Owner().String(), Blocks: blocks, }) ph.Release() } // Sort the resulting sequence by model name, then owner. sort.Sort(orderedBlockInfo(results.Models)) return results, nil }
c3967
controllerState.Model() if err != nil { return result, errors.Trace(err) } cfg, err := controllerModel.Config() if err != nil { return result, errors.Trace(err) } result.Config = make(map[string]params.ConfigValue) for name, val := range cfg.AllAttrs() { result.Config[name] = params.ConfigValue{ Value: val, } } return result, nil }
c3968
model.Name(), OwnerTag: model.Owner().String(), } modelConf, err := model.Config() if err != nil { config.Error = common.ServerError(err) } else { config.Config = modelConf.AllAttrs() } cloudSpec := c.GetCloudSpec(model.ModelTag()) if config.Error == nil { config.CloudSpec = cloudSpec.Result config.Error = cloudSpec.Error } result.Models = append(result.Models, config) } return result, nil }
c3969
c.state.WatchAllModels(c.statePool) return params.AllWatcherId{ AllWatcherId: c.resources.Register(w), }, nil }
c3970
{ results.Results[i].Error = common.ServerError(common.ErrPerm) continue } access, err := c.state.UserPermission(userTag, c.state.ControllerTag()) if err != nil { results.Results[i].Error = common.ServerError(err) continue } results.Results[i].Result = &params.UserAccess{ Access: string(access), UserTag: userTag.String()} } return results, nil }
c3971
spec.ModelTag id, err := c.initiateOneMigration(spec) if err != nil { result.Error = common.ServerError(err) } else { result.MigrationId = id } } return out, nil }
c3972
// Backwards compatibility requires us to accept add-model. if controllerAccess != permission.AddModelAccess { result.Results[i].Error = common.ServerError(err) continue } } targetUserTag, err := names.ParseUserTag(arg.UserTag) if err != nil { result.Results[i].Error = common.ServerError(errors.Annotate(err, "could not modify controller access")) continue } result.Results[i].Error = common.ServerError( ChangeControllerAccess(c.state, c.apiUser, targetUserTag, arg.Action, controllerAccess)) } return result, nil }
c3973
version to controller config to allow for // simultaneous updates and races in publishing, potentially across // HA servers. cfg, err := c.state.ControllerConfig() if err != nil { return errors.Trace(err) } if _, err := c.hub.Publish( controller.ConfigChanged, controller.ConfigChangedMessage{cfg}); err != nil { return errors.Trace(err) } return nil }
c3974
// Conflicts with prior check, must be inconsistent state. err = txn.ErrExcessiveContention } if err != nil { return errors.Annotate(err, "could not look up cloud access for user") } // Only set access if greater access is being granted. if cloudAccess.EqualOrGreaterCloudAccessThan(access) { return errors.Errorf("user already has %q access or greater", access) } if _, err = accessor.SetUserAccess(targetUserTag, names.NewCloudTag(cloud), access); err != nil { return errors.Annotate(err, "could not set cloud access for user") } return nil } if err != nil { return errors.Trace(err) } return nil }
c3975
controller access") } return nil case params.RevokeControllerAccess: return revokeControllerAccess(accessor, targetUserTag, apiUser, access) default: return errors.Errorf("unknown action %q", action) } }
c3976
return errors.Annotatef(err, "cannot check lease %q", t.leaseKey.Lease) } if err := t.secretary.CheckHolder(t.holderName); err != nil { return errors.Annotatef(err, "cannot check holder %q", t.holderName) } return check{ leaseKey: t.leaseKey, holderName: t.holderName, attempt: attempt, trapdoorKey: trapdoorKey, response: make(chan error), stop: t.stop, }.invoke(t.checks) }
c3977
case err := <-c.response: return errors.Trace(err) } } }
c3978
<-c.stop: case c.response <- err: } }
c3979
utils.VerifySSLHostnames, simplestreams.DEFAULT_CLOUD_DATA, requireSigned) }
c3980
}, } items, _, err := simplestreams.GetMetadata(sources, params) if err != nil { return nil, errors.Annotate(err, "error fetching simplestreams metadata") } allMeta := make([]*Metadata, len(items)) for i, item := range items { allMeta[i] = item.(*Metadata) } sort.Sort(byVersion(allMeta)) return allMeta, nil }
c3981
errors.Annotate(err, "cannot retrieve metadata full path") } meta.FullPath = fullPath vers, err := version.Parse(meta.StringVersion) if err != nil { return nil, errors.Annotate(err, "cannot parse metadata version") } meta.Version = vers meta.Source = source matchingItems = append(matchingItems, meta) } return matchingItems, nil }
c3982
storageProvisionerFacade) return &State{facadeCaller}, nil }
c3983
st.watchStorageEntities("WatchVolumes", scope) }
c3984
st.watchAttachments("WatchVolumeAttachments", scope, apiwatcher.NewVolumeAttachmentsWatcher) }
c3985
st.watchAttachments("WatchVolumeAttachmentPlans", scope, apiwatcher.NewVolumeAttachmentPlansWatcher) }
c3986
st.watchAttachments("WatchFilesystemAttachments", scope, apiwatcher.NewFilesystemAttachmentsWatcher) }
c3987
} if len(results.Results) != len(ids) { return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results)) } return results.Results, nil }
c3988
nil { return nil, err } if len(results.Results) != len(tags) { return nil, errors.Errorf("expected %d result(s), got %d", len(tags), len(results.Results)) } return results.Results, nil }
c3989
} if len(results.Results) != len(ids) { return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results)) } return results.Results, nil }
c3990
} if len(results.Results) != len(ids) { return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results)) } return results.Results, nil }
c3991
{ return nil, err } if len(results.Results) != len(tags) { return nil, errors.Errorf("expected %d result(s), got %d", len(tags), len(results.Results)) } return results.Results, nil }
c3992
!= len(ids) { return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results)) } return results.Results, nil }
c3993
{ return nil, err } if len(results.Results) != len(tags) { return nil, errors.Errorf("expected %d result(s), got %d", len(tags), len(results.Results)) } return results.Results, nil }
c3994
!= len(ids) { return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results)) } return results.Results, nil }
c3995
!= nil { return nil, errors.Trace(err) } if len(results.Results) != 1 { return nil, errors.Errorf("expected %d result(s), got %d", len(results.Results), len(tags)) } return results.Results, nil }
c3996
params.SetStatus{args}, &result) if err != nil { return err } return result.Combine() }
c3997
make(chan []string), } err := catacomb.Invoke(catacomb.Plan{ Site: &w.catacomb, Work: w.loop, }) return w, errors.Trace(err) }
c3998
!= nil { return err } } return nil }
c3999
case hooks.StorageAttached, hooks.StorageDetaching: if !names.IsValidStorage(hi.StorageId) { return fmt.Errorf("invalid storage ID %q", hi.StorageId) } return nil // TODO(fwereade): define these in charm/hooks... case LeaderElected, LeaderDeposed, LeaderSettingsChanged: return nil } return fmt.Errorf("unknown hook kind %q", hi.Kind) }