_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q178800 | AddRoute | test | func (t *Trie) AddRoute(httpMethod, pathExp string, route interface{}) error {
return t.root.addRoute(httpMethod, pathExp, route, []string{})
} | go | {
"resource": ""
} |
q178801 | printDebug | test | func (t *Trie) printDebug() {
fmt.Print("<trie>\n")
t.root.printDebug(0)
fmt.Print("</trie>\n")
} | go | {
"resource": ""
} |
q178802 | FindRoutes | test | func (t *Trie) FindRoutes(httpMethod, path string) []*Match {
context := newFindContext()
matches := []*Match{}
context.matchFunc = func(httpMethod, path string, node *node) {
if node.HttpMethodToRoute[httpMethod] != nil {
// path and method match, found a route !
matches = append(
matches,
&Match{
... | go | {
"resource": ""
} |
q178803 | FindRoutesAndPathMatched | test | func (t *Trie) FindRoutesAndPathMatched(httpMethod, path string) ([]*Match, bool) {
context := newFindContext()
pathMatched := false
matches := []*Match{}
context.matchFunc = func(httpMethod, path string, node *node) {
pathMatched = true
if node.HttpMethodToRoute[httpMethod] != nil {
// path and method match... | go | {
"resource": ""
} |
q178804 | FindRoutesForPath | test | func (t *Trie) FindRoutesForPath(path string) []*Match {
context := newFindContext()
matches := []*Match{}
context.matchFunc = func(httpMethod, path string, node *node) {
params := context.paramsAsMap()
for _, route := range node.HttpMethodToRoute {
matches = append(
matches,
&Match{
Route: rout... | go | {
"resource": ""
} |
q178805 | Use | test | func (api *Api) Use(middlewares ...Middleware) {
api.stack = append(api.stack, middlewares...)
} | go | {
"resource": ""
} |
q178806 | MakeHandler | test | func (api *Api) MakeHandler() http.Handler {
var appFunc HandlerFunc
if api.app != nil {
appFunc = api.app.AppFunc()
} else {
appFunc = func(w ResponseWriter, r *Request) {}
}
return http.HandlerFunc(
adapterFunc(
WrapMiddlewares(api.stack, appFunc),
),
)
} | go | {
"resource": ""
} |
q178807 | MiddlewareFunc | test | func (mw *PoweredByMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
poweredBy := xPoweredByDefault
if mw.XPoweredBy != "" {
poweredBy = mw.XPoweredBy
}
return func(w ResponseWriter, r *Request) {
w.Header().Add("X-Powered-By", poweredBy)
// call the handler
h(w, r)
}
} | go | {
"resource": ""
} |
q178808 | MiddlewareFunc | test | func (mw *StatusMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
mw.start = time.Now()
mw.pid = os.Getpid()
mw.responseCounts = map[string]int{}
mw.totalResponseTime = time.Time{}
return func(w ResponseWriter, r *Request) {
// call the handler
h(w, r)
if r.Env["STATUS_CODE"] == nil {
log.Fatal(... | go | {
"resource": ""
} |
q178809 | GetStatus | test | func (mw *StatusMiddleware) GetStatus() *Status {
mw.lock.RLock()
now := time.Now()
uptime := now.Sub(mw.start)
totalCount := 0
for _, count := range mw.responseCounts {
totalCount += count
}
totalResponseTime := mw.totalResponseTime.Sub(time.Time{})
averageResponseTime := time.Duration(0)
if totalCoun... | go | {
"resource": ""
} |
q178810 | MiddlewareFunc | test | func (mw *JsonpMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
if mw.CallbackNameKey == "" {
mw.CallbackNameKey = "callback"
}
return func(w ResponseWriter, r *Request) {
callbackName := r.URL.Query().Get(mw.CallbackNameKey)
// TODO validate the callbackName ?
if callbackName != "" {
// the cl... | go | {
"resource": ""
} |
q178811 | Flush | test | func (w *jsonpResponseWriter) Flush() {
if !w.wroteHeader {
w.WriteHeader(http.StatusOK)
}
flusher := w.ResponseWriter.(http.Flusher)
flusher.Flush()
} | go | {
"resource": ""
} |
q178812 | MiddlewareFunc | test | func (mw *AccessLogJsonMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
// set the default Logger
if mw.Logger == nil {
mw.Logger = log.New(os.Stderr, "", 0)
}
return func(w ResponseWriter, r *Request) {
// call the handler
h(w, r)
mw.Logger.Printf("%s", makeAccessLogJsonRecord(r).asJson())
}
} | go | {
"resource": ""
} |
q178813 | Fetch | test | func (s *S3) Fetch() (io.Reader, error) {
//delay fetches after first
if s.delay {
time.Sleep(s.Interval)
}
s.delay = true
//status check using HEAD
head, err := s.client.HeadObject(&s3.HeadObjectInput{Bucket: &s.Bucket, Key: &s.Key})
if err != nil {
return nil, fmt.Errorf("HEAD request failed (%s)", err)
}... | go | {
"resource": ""
} |
q178814 | sanityCheck | test | func sanityCheck() bool {
//sanity check
if token := os.Getenv(envBinCheck); token != "" {
fmt.Fprint(os.Stdout, token)
return true
}
//legacy sanity check using old env var
if token := os.Getenv(envBinCheckLegacy); token != "" {
fmt.Fprint(os.Stdout, token)
return true
}
return false
} | go | {
"resource": ""
} |
q178815 | release | test | func (l *overseerListener) release(timeout time.Duration) {
//stop accepting connections - release fd
l.closeError = l.Listener.Close()
//start timer, close by force if deadline not met
waited := make(chan bool)
go func() {
l.wg.Wait()
waited <- true
}()
go func() {
select {
case <-time.After(timeout):
... | go | {
"resource": ""
} |
q178816 | fetchLoop | test | func (mp *master) fetchLoop() {
min := mp.Config.MinFetchInterval
time.Sleep(min)
for {
t0 := time.Now()
mp.fetch()
//duration fetch of fetch
diff := time.Now().Sub(t0)
if diff < min {
delay := min - diff
//ensures at least MinFetchInterval delay.
//should be throttled by the fetcher!
time.Slee... | go | {
"resource": ""
} |
q178817 | forkLoop | test | func (mp *master) forkLoop() error {
//loop, restart command
for {
if err := mp.fork(); err != nil {
return err
}
}
} | go | {
"resource": ""
} |
q178818 | Init | test | func (f *File) Init() error {
if f.Path == "" {
return fmt.Errorf("Path required")
}
if f.Interval < 1*time.Second {
f.Interval = 1 * time.Second
}
if err := f.updateHash(); err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q178819 | Fetch | test | func (f *File) Fetch() (io.Reader, error) {
//only delay after first fetch
if f.delay {
time.Sleep(f.Interval)
}
f.delay = true
lastHash := f.hash
if err := f.updateHash(); err != nil {
return nil, err
}
// no change
if lastHash == f.hash {
return nil, nil
}
// changed!
file, err := os.Open(f.Path)
i... | go | {
"resource": ""
} |
q178820 | Fetch | test | func (h *HTTP) Fetch() (io.Reader, error) {
//delay fetches after first
if h.delay {
time.Sleep(h.Interval)
}
h.delay = true
//status check using HEAD
resp, err := http.Head(h.URL)
if err != nil {
return nil, fmt.Errorf("HEAD request failed (%s)", err)
}
resp.Body.Close()
if resp.StatusCode != http.Status... | go | {
"resource": ""
} |
q178821 | NewConfig | test | func NewConfig() *Config {
c := &Config{
Config: *sarama.NewConfig(),
}
c.Group.PartitionStrategy = StrategyRange
c.Group.Offsets.Retry.Max = 3
c.Group.Offsets.Synchronization.DwellTime = c.Consumer.MaxProcessingTime
c.Group.Session.Timeout = 30 * time.Second
c.Group.Heartbeat.Interval = 3 * time.Second
c.Con... | go | {
"resource": ""
} |
q178822 | Validate | test | func (c *Config) Validate() error {
if c.Group.Heartbeat.Interval%time.Millisecond != 0 {
sarama.Logger.Println("Group.Heartbeat.Interval only supports millisecond precision; nanoseconds will be truncated.")
}
if c.Group.Session.Timeout%time.Millisecond != 0 {
sarama.Logger.Println("Group.Session.Timeout only su... | go | {
"resource": ""
} |
q178823 | NewClient | test | func NewClient(addrs []string, config *Config) (*Client, error) {
if config == nil {
config = NewConfig()
}
if err := config.Validate(); err != nil {
return nil, err
}
client, err := sarama.NewClient(addrs, &config.Config)
if err != nil {
return nil, err
}
return &Client{Client: client, config: *config... | go | {
"resource": ""
} |
q178824 | AsyncClose | test | func (c *partitionConsumer) AsyncClose() {
c.closeOnce.Do(func() {
c.closeErr = c.PartitionConsumer.Close()
close(c.dying)
})
} | go | {
"resource": ""
} |
q178825 | Close | test | func (c *partitionConsumer) Close() error {
c.AsyncClose()
<-c.dead
return c.closeErr
} | go | {
"resource": ""
} |
q178826 | MarkOffset | test | func (c *partitionConsumer) MarkOffset(offset int64, metadata string) {
c.mu.Lock()
if next := offset + 1; next > c.state.Info.Offset {
c.state.Info.Offset = next
c.state.Info.Metadata = metadata
c.state.Dirty = true
}
c.mu.Unlock()
} | go | {
"resource": ""
} |
q178827 | NewConsumer | test | func NewConsumer(addrs []string, groupID string, topics []string, config *Config) (*Consumer, error) {
client, err := NewClient(addrs, config)
if err != nil {
return nil, err
}
consumer, err := NewConsumerFromClient(client, groupID, topics)
if err != nil {
return nil, err
}
consumer.ownClient = true
return... | go | {
"resource": ""
} |
q178828 | MarkOffsets | test | func (c *Consumer) MarkOffsets(s *OffsetStash) {
s.mu.Lock()
defer s.mu.Unlock()
for tp, info := range s.offsets {
if sub := c.subs.Fetch(tp.Topic, tp.Partition); sub != nil {
sub.MarkOffset(info.Offset, info.Metadata)
}
delete(s.offsets, tp)
}
} | go | {
"resource": ""
} |
q178829 | ResetOffset | test | func (c *Consumer) ResetOffset(msg *sarama.ConsumerMessage, metadata string) {
if sub := c.subs.Fetch(msg.Topic, msg.Partition); sub != nil {
sub.ResetOffset(msg.Offset, metadata)
}
} | go | {
"resource": ""
} |
q178830 | Close | test | func (c *Consumer) Close() (err error) {
c.closeOnce.Do(func() {
close(c.dying)
<-c.dead
if e := c.release(); e != nil {
err = e
}
if e := c.consumer.Close(); e != nil {
err = e
}
close(c.messages)
close(c.errors)
if e := c.leaveGroup(); e != nil {
err = e
}
close(c.partitions)
close... | go | {
"resource": ""
} |
q178831 | hbLoop | test | func (c *Consumer) hbLoop(stopped <-chan none) {
ticker := time.NewTicker(c.client.config.Group.Heartbeat.Interval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
switch err := c.heartbeat(); err {
case nil, sarama.ErrNoError:
case sarama.ErrNotCoordinatorForConsumer, sarama.ErrRebalanceInProgress... | go | {
"resource": ""
} |
q178832 | twLoop | test | func (c *Consumer) twLoop(stopped <-chan none) {
ticker := time.NewTicker(c.client.config.Metadata.RefreshFrequency / 2)
defer ticker.Stop()
for {
select {
case <-ticker.C:
topics, err := c.client.Topics()
if err != nil {
c.handleError(&Error{Ctx: "topics", error: err})
return
}
for _, topi... | go | {
"resource": ""
} |
q178833 | cmLoop | test | func (c *Consumer) cmLoop(stopped <-chan none) {
ticker := time.NewTicker(c.client.config.Consumer.Offsets.CommitInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if err := c.commitOffsetsWithRetry(c.client.config.Group.Offsets.Retry.Max); err != nil {
c.handleError(&Error{Ctx: "commit", erro... | go | {
"resource": ""
} |
q178834 | fetchOffsets | test | func (c *Consumer) fetchOffsets(subs map[string][]int32) (map[string]map[int32]offsetInfo, error) {
offsets := make(map[string]map[int32]offsetInfo, len(subs))
req := &sarama.OffsetFetchRequest{
Version: 1,
ConsumerGroup: c.groupID,
}
for topic, partitions := range subs {
offsets[topic] = make(map[int3... | go | {
"resource": ""
} |
q178835 | MarkOffset | test | func (s *OffsetStash) MarkOffset(msg *sarama.ConsumerMessage, metadata string) {
s.MarkPartitionOffset(msg.Topic, msg.Partition, msg.Offset, metadata)
} | go | {
"resource": ""
} |
q178836 | ResetOffset | test | func (s *OffsetStash) ResetOffset(msg *sarama.ConsumerMessage, metadata string) {
s.ResetPartitionOffset(msg.Topic, msg.Partition, msg.Offset, metadata)
} | go | {
"resource": ""
} |
q178837 | Offsets | test | func (s *OffsetStash) Offsets() map[string]int64 {
s.mu.Lock()
defer s.mu.Unlock()
res := make(map[string]int64, len(s.offsets))
for tp, info := range s.offsets {
res[tp.String()] = info.Offset
}
return res
} | go | {
"resource": ""
} |
q178838 | Actual | test | func (r *InstanceGroup) Actual(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("instanceGroup.Actual")
if r.CachedActual != nil {
logger.Debug("Using cached instance [actual]")
return immutable, r.CachedActual, nil
}
newResource := &InstanceGroup{
Shared: Shared{
Name: ... | go | {
"resource": ""
} |
q178839 | Expected | test | func (r *InstanceGroup) Expected(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("instanceGroup.Expected")
if r.CachedExpected != nil {
logger.Debug("Using instance subnet [expected]")
return immutable, r.CachedExpected, nil
}
expected := &InstanceGroup{
Shared: Shared{
... | go | {
"resource": ""
} |
q178840 | Delete | test | func (r *InstanceGroup) Delete(actual cloud.Resource, immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("instanceGroup.Delete")
deleteResource := actual.(*InstanceGroup)
if deleteResource.Name == "" {
return nil, nil, fmt.Errorf("Unable to delete instance resource without Name [%... | go | {
"resource": ""
} |
q178841 | GetReconciler | test | func GetReconciler(known *cluster.Cluster, runtimeParameters *RuntimeParameters) (reconciler cloud.Reconciler, err error) {
switch known.ProviderConfig().Cloud {
case cluster.CloudGoogle:
sdk, err := googleSDK.NewSdk()
if err != nil {
return nil, err
}
gr.Sdk = sdk
return cloud.NewAtomicReconciler(known,... | go | {
"resource": ""
} |
q178842 | GetVersion | test | func GetVersion() *Version {
return &Version{
Version: KubicornVersion,
GitCommit: GitSha,
BuildDate: time.Now().UTC().String(),
GoVersion: runtime.Version(),
GOOS: runtime.GOOS,
GOArch: runtime.GOARCH,
}
} | go | {
"resource": ""
} |
q178843 | GetVersionJSON | test | func GetVersionJSON() string {
verBytes, err := json.Marshal(GetVersion())
if err != nil {
logger.Critical("Unable to marshal version struct: %v", err)
}
return string(verBytes)
} | go | {
"resource": ""
} |
q178844 | Actual | test | func (r *ResourceGroup) Actual(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("resourcegroup.Actual")
newResource := &ResourceGroup{
Shared: Shared{
Name: r.Name,
Tags: r.Tags,
Identifier: immutable.ProviderConfig().GroupIdentifier,
},
Location: r.Locat... | go | {
"resource": ""
} |
q178845 | Expected | test | func (r *ResourceGroup) Expected(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("resourcegroup.Expected")
newResource := &ResourceGroup{
Shared: Shared{
Name: immutable.Name,
Tags: r.Tags,
Identifier: immutable.ProviderConfig().GroupIdentifier,
},
Locat... | go | {
"resource": ""
} |
q178846 | CreateCmd | test | func CreateCmd() *cobra.Command {
var co = &cli.CreateOptions{}
var createCmd = &cobra.Command{
Use: "create [NAME] [-p|--profile PROFILENAME] [-c|--cloudid CLOUDID]",
Short: "Create a Kubicorn API model from a profile",
Long: `Use this command to create a Kubicorn API model in a defined state store.
This c... | go | {
"resource": ""
} |
q178847 | NewUbuntuCluster | test | func NewUbuntuCluster(name string) *cluster.Cluster {
controlPlaneProviderConfig := &cluster.ControlPlaneProviderConfig{
Cloud: cluster.CloudAzure,
Location: "eastus",
SSH: &cluster.SSH{
PublicKeyPath: "~/.ssh/id_rsa.pub",
User: "root",
},
KubernetesAPI: &cluster.KubernetesAPI{
Port: "4... | go | {
"resource": ""
} |
q178848 | ProviderConfig | test | func (c *Cluster) ProviderConfig() *ControlPlaneProviderConfig {
//providerConfig providerConfig
raw := c.ClusterAPI.Spec.ProviderConfig
providerConfig := &ControlPlaneProviderConfig{}
err := json.Unmarshal([]byte(raw), providerConfig)
if err != nil {
logger.Critical("Unable to unmarshal provider config: %v", er... | go | {
"resource": ""
} |
q178849 | SetProviderConfig | test | func (c *Cluster) SetProviderConfig(config *ControlPlaneProviderConfig) error {
bytes, err := json.Marshal(config)
if err != nil {
logger.Critical("Unable to marshal provider config: %v", err)
return err
}
str := string(bytes)
c.ClusterAPI.Spec.ProviderConfig = str
return nil
} | go | {
"resource": ""
} |
q178850 | MachineProviderConfigs | test | func (c *Cluster) MachineProviderConfigs() []*MachineProviderConfig {
var providerConfigs []*MachineProviderConfig
for _, machineSet := range c.MachineSets {
raw := machineSet.Spec.Template.Spec.ProviderConfig
providerConfig := &MachineProviderConfig{}
err := json.Unmarshal([]byte(raw), providerConfig)
if err... | go | {
"resource": ""
} |
q178851 | SetMachineProviderConfigs | test | func (c *Cluster) SetMachineProviderConfigs(providerConfigs []*MachineProviderConfig) {
for _, providerConfig := range providerConfigs {
name := providerConfig.ServerPool.Name
found := false
for _, machineSet := range c.MachineSets {
if machineSet.Name == name {
//logger.Debug("Matched machine set to prov... | go | {
"resource": ""
} |
q178852 | NewCluster | test | func NewCluster(name string) *Cluster {
return &Cluster{
Name: name,
ClusterAPI: &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: clusterv1.ClusterSpec{},
},
ControlPlane: &clusterv1.MachineSet{},
}
} | go | {
"resource": ""
} |
q178853 | DeployControllerCmd | test | func DeployControllerCmd() *cobra.Command {
var dco = &cli.DeployControllerOptions{}
var deployControllerCmd = &cobra.Command{
Use: "deploycontroller <NAME>",
Short: "Deploy a controller for a given cluster",
Long: `Use this command to deploy a controller for a given cluster.
As long as a controller is defin... | go | {
"resource": ""
} |
q178854 | NewRetrier | test | func NewRetrier(retries, sleepSeconds int, retryable Retryable) *Retrier {
return &Retrier{
retries: retries,
sleepSeconds: sleepSeconds,
retryable: retryable,
}
} | go | {
"resource": ""
} |
q178855 | RunRetry | test | func (r *Retrier) RunRetry() error {
// Start signal handler.
sigHandler := signals.NewSignalHandler(10)
go sigHandler.Register()
finish := make(chan bool, 1)
go func() {
select {
case <-finish:
return
case <-time.After(10 * time.Second):
return
default:
for {
if sigHandler.GetState() != 0 {
... | go | {
"resource": ""
} |
q178856 | MustGenerateRandomBytes | test | func MustGenerateRandomBytes(length int) []byte {
res, err := GenerateRandomBytes(length)
if err != nil {
panic("Could not generate random bytes")
}
return res
} | go | {
"resource": ""
} |
q178857 | ExplainCmd | test | func ExplainCmd() *cobra.Command {
var exo = &cli.ExplainOptions{}
var cmd = &cobra.Command{
Use: "explain",
Short: "Explain cluster",
Long: `Output expected and actual state of the given cluster`,
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
exo.Name = viper.GetStri... | go | {
"resource": ""
} |
q178858 | TimeOrderedUUID | test | func TimeOrderedUUID() string {
unixTime := uint32(time.Now().UTC().Unix())
return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
unixTime,
rand.MustGenerateRandomBytes(2),
rand.MustGenerateRandomBytes(2),
rand.MustGenerateRandomBytes(2),
rand.MustGenerateRandomBytes(2),
rand.MustGenerateRandomBytes(4))
} | go | {
"resource": ""
} |
q178859 | GetConfigCmd | test | func GetConfigCmd() *cobra.Command {
var cro = &cli.GetConfigOptions{}
var getConfigCmd = &cobra.Command{
Use: "getconfig <NAME>",
Short: "Manage Kubernetes configuration",
Long: `Use this command to pull a kubeconfig file from a cluster so you can use kubectl.
This command will attempt to find a cluster, ... | go | {
"resource": ""
} |
q178860 | RunAnnotated | test | func RunAnnotated(task Task, description string, symbol string, options ...interface{}) error {
doneCh := make(chan bool)
errCh := make(chan error)
l := logger.Log
t := DefaultTicker
for _, o := range options {
if value, ok := o.(logger.Logger); ok {
l = value
} else if value, ok := o.(*time.Ticker); ok {... | go | {
"resource": ""
} |
q178861 | ListCmd | test | func ListCmd() *cobra.Command {
var lo = &cli.ListOptions{}
var cmd = &cobra.Command{
Use: "list",
Short: "List available states",
Long: `List the states available in the _state directory`,
Run: func(cmd *cobra.Command, args []string) {
if err := runList(lo); err != nil {
logger.Critical(err.Error()... | go | {
"resource": ""
} |
q178862 | NewUbuntuCluster | test | func NewUbuntuCluster(name string) *cluster.Cluster {
controlPlaneProviderConfig := &cluster.ControlPlaneProviderConfig{
Cloud: cluster.CloudPacket,
Project: &cluster.Project{
Name: fmt.Sprintf("kubicorn-%s", name),
},
Location: "ewr1",
SSH: &cluster.SSH{
PublicKeyPath: "~/.ssh/id_rsa.pub",
User: ... | go | {
"resource": ""
} |
q178863 | EditCmd | test | func EditCmd() *cobra.Command {
var eo = &cli.EditOptions{}
var editCmd = &cobra.Command{
Use: "edit <NAME>",
Short: "Edit a cluster state",
Long: `Use this command to edit a state.`,
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
eo.Name = viper.GetString(keyKubicornNa... | go | {
"resource": ""
} |
q178864 | RemoveKey | test | func (k *Keyring) RemoveKey(key ssh.PublicKey) error {
return k.Agent.Remove(key)
} | go | {
"resource": ""
} |
q178865 | RemoveKeyUsingFile | test | func (k *Keyring) RemoveKeyUsingFile(pubkey string) error {
p, err := ioutil.ReadFile(pubkey)
if err != nil {
return err
}
key, _, _, _, _ := ssh.ParseAuthorizedKey(p)
if err != nil {
return err
}
return k.RemoveKey(key)
} | go | {
"resource": ""
} |
q178866 | Actual | test | func (r *Firewall) Actual(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("firewall.Actual")
newResource := defaultFirewallStruct()
// Digital Firewalls.Get requires firewall ID, which we will not always have.thats why using List.
firewalls, _, err := Sdk.Client.Firewalls.List(... | go | {
"resource": ""
} |
q178867 | Expected | test | func (r *Firewall) Expected(immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("firewall.Expected")
newResource := &Firewall{
Shared: Shared{
Name: r.Name,
CloudID: r.ServerPool.Identifier,
},
InboundRules: r.InboundRules,
OutboundRules: r.OutboundRules,
DropletID... | go | {
"resource": ""
} |
q178868 | Apply | test | func (r *Firewall) Apply(actual, expected cloud.Resource, immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("firewall.Apply")
expectedResource := expected.(*Firewall)
actualResource := actual.(*Firewall)
isEqual, err := compare.IsEqual(actualResource, expectedResource)
if err !=... | go | {
"resource": ""
} |
q178869 | Delete | test | func (r *Firewall) Delete(actual cloud.Resource, immutable *cluster.Cluster) (*cluster.Cluster, cloud.Resource, error) {
logger.Debug("firewall.Delete")
deleteResource, ok := actual.(*Firewall)
if !ok {
return nil, nil, fmt.Errorf("failed to type convert actual Firewall type ")
}
if deleteResource.Name == "" {
... | go | {
"resource": ""
} |
q178870 | DeleteCmd | test | func DeleteCmd() *cobra.Command {
var do = &cli.DeleteOptions{}
var deleteCmd = &cobra.Command{
Use: "delete <NAME>",
Short: "Delete a Kubernetes cluster",
Long: `Use this command to delete cloud resources.
This command will attempt to build the resource graph based on an API model.
Once the graph is buil... | go | {
"resource": ""
} |
q178871 | NewStateStore | test | func (options Options) NewStateStore() (state.ClusterStorer, error) {
var stateStore state.ClusterStorer
switch options.StateStore {
case "fs":
logger.Info("Selected [fs] state store")
stateStore = fs.NewFileSystemStore(&fs.FileSystemStoreOptions{
BasePath: options.StateStorePath,
ClusterName: options.... | go | {
"resource": ""
} |
q178872 | Commit | test | func (git *JSONGitStore) Commit(c *cluster.Cluster) error {
if c == nil {
return fmt.Errorf("Nil cluster spec")
}
bytes, err := json.Marshal(c)
if err != nil {
return err
}
//writes latest changes to git repo.
git.Write(state.ClusterJSONFile, bytes)
//commits the changes
r, err := g.NewFilesystemReposito... | go | {
"resource": ""
} |
q178873 | ApplyCmd | test | func ApplyCmd() *cobra.Command {
var ao = &cli.ApplyOptions{}
var applyCmd = &cobra.Command{
Use: "apply <NAME>",
Short: "Apply a cluster resource to a cloud",
Long: `Use this command to apply an API model in a cloud.
This command will attempt to find an API model in a defined state store, and then apply an... | go | {
"resource": ""
} |
q178874 | ExpandPath | test | func ExpandPath(path string) string {
switch path {
case ".":
wd, err := os.Getwd()
if err != nil {
logger.Critical("Unable to get current working directory: %v", err)
return ""
}
path = wd
case "~":
homeVar := os.Getenv("HOME")
if homeVar == "" {
homeUser, err := user.Current()
if err != nil... | go | {
"resource": ""
} |
q178875 | CompletionCmd | test | func CompletionCmd() *cobra.Command {
return &cobra.Command{
Use: "completion",
Short: "Generate completion code for bash and zsh shells.",
Long: `completion is used to output completion code for bash and zsh shells.
Before using completion features, you have to source completion code
from your .profile. T... | go | {
"resource": ""
} |
q178876 | AdoptCmd | test | func AdoptCmd() *cobra.Command {
return &cobra.Command{
Use: "adopt",
Short: "Adopt a Kubernetes cluster into a Kubicorn state store",
Long: `Use this command to audit and adopt a Kubernetes cluster into a Kubicorn state store.
This command will query cloud resources and attempt to build a representation of... | go | {
"resource": ""
} |
q178877 | StrEnvDef | test | func StrEnvDef(env string, def string) string {
val := os.Getenv(env)
if val == "" {
return def
}
return val
} | go | {
"resource": ""
} |
q178878 | IntEnvDef | test | func IntEnvDef(env string, def int) int {
val := os.Getenv(env)
if val == "" {
return def
}
ival, err := strconv.Atoi(val)
if err != nil {
return def
}
return ival
} | go | {
"resource": ""
} |
q178879 | BoolEnvDef | test | func BoolEnvDef(env string, def bool) bool {
val := os.Getenv(env)
if val == "" {
return def
}
b, err := strconv.ParseBool(val)
if err != nil {
return def
}
return b
} | go | {
"resource": ""
} |
q178880 | readFromFS | test | func readFromFS(sourcePath string) (string, error) {
// If sourcePath starts with ~ we search for $HOME
// and preppend it to the absolutePath overwriting the first character
// TODO: Add Windows support
if strings.HasPrefix(sourcePath, "~") {
homeDir := os.Getenv("HOME")
if homeDir == "" {
return "", fmt.E... | go | {
"resource": ""
} |
q178881 | VersionCmd | test | func VersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Verify Kubicorn version",
Long: `Use this command to check the version of Kubicorn.
This command will return the version of the Kubicorn binary.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n", version.... | go | {
"resource": ""
} |
q178882 | NewSignalHandler | test | func NewSignalHandler(timeoutSeconds int) *Handler {
signals := make(chan os.Signal)
signal.Notify(signals, os.Interrupt, os.Kill)
return &Handler{
timeoutSeconds: timeoutSeconds,
signals: signals,
signalReceived: 0,
}
} | go | {
"resource": ""
} |
q178883 | Register | test | func (h *Handler) Register() {
go func() {
h.timer = time.NewTimer(time.Duration(h.timeoutSeconds) * time.Second)
for {
select {
case s := <-h.signals:
switch {
case s == os.Interrupt:
if h.signalReceived == 0 {
h.signalReceived = 1
logger.Debug("SIGINT Received")
continue
... | go | {
"resource": ""
} |
q178884 | NewUbuntuCluster | test | func NewUbuntuCluster(name string) *cluster.Cluster {
var (
masterName = fmt.Sprintf("%s-master", name)
nodeName = fmt.Sprintf("%s-node", name)
)
controlPlaneProviderConfig := &cluster.ControlPlaneProviderConfig{
Cloud: cluster.CloudECS,
Location: "nl-ams1",
SSH: &cluster.SSH{
PublicKeyPath: "~/.ss... | go | {
"resource": ""
} |
q178885 | BeginningOfHour | test | func (now *Now) BeginningOfHour() time.Time {
y, m, d := now.Date()
return time.Date(y, m, d, now.Time.Hour(), 0, 0, 0, now.Time.Location())
} | go | {
"resource": ""
} |
q178886 | BeginningOfDay | test | func (now *Now) BeginningOfDay() time.Time {
y, m, d := now.Date()
return time.Date(y, m, d, 0, 0, 0, 0, now.Time.Location())
} | go | {
"resource": ""
} |
q178887 | BeginningOfWeek | test | func (now *Now) BeginningOfWeek() time.Time {
t := now.BeginningOfDay()
weekday := int(t.Weekday())
if WeekStartDay != time.Sunday {
weekStartDayInt := int(WeekStartDay)
if weekday < weekStartDayInt {
weekday = weekday + 7 - weekStartDayInt
} else {
weekday = weekday - weekStartDayInt
}
}
return t.... | go | {
"resource": ""
} |
q178888 | BeginningOfMonth | test | func (now *Now) BeginningOfMonth() time.Time {
y, m, _ := now.Date()
return time.Date(y, m, 1, 0, 0, 0, 0, now.Location())
} | go | {
"resource": ""
} |
q178889 | BeginningOfQuarter | test | func (now *Now) BeginningOfQuarter() time.Time {
month := now.BeginningOfMonth()
offset := (int(month.Month()) - 1) % 3
return month.AddDate(0, -offset, 0)
} | go | {
"resource": ""
} |
q178890 | BeginningOfYear | test | func (now *Now) BeginningOfYear() time.Time {
y, _, _ := now.Date()
return time.Date(y, time.January, 1, 0, 0, 0, 0, now.Location())
} | go | {
"resource": ""
} |
q178891 | EndOfMinute | test | func (now *Now) EndOfMinute() time.Time {
return now.BeginningOfMinute().Add(time.Minute - time.Nanosecond)
} | go | {
"resource": ""
} |
q178892 | EndOfHour | test | func (now *Now) EndOfHour() time.Time {
return now.BeginningOfHour().Add(time.Hour - time.Nanosecond)
} | go | {
"resource": ""
} |
q178893 | EndOfDay | test | func (now *Now) EndOfDay() time.Time {
y, m, d := now.Date()
return time.Date(y, m, d, 23, 59, 59, int(time.Second-time.Nanosecond), now.Location())
} | go | {
"resource": ""
} |
q178894 | EndOfWeek | test | func (now *Now) EndOfWeek() time.Time {
return now.BeginningOfWeek().AddDate(0, 0, 7).Add(-time.Nanosecond)
} | go | {
"resource": ""
} |
q178895 | EndOfMonth | test | func (now *Now) EndOfMonth() time.Time {
return now.BeginningOfMonth().AddDate(0, 1, 0).Add(-time.Nanosecond)
} | go | {
"resource": ""
} |
q178896 | EndOfQuarter | test | func (now *Now) EndOfQuarter() time.Time {
return now.BeginningOfQuarter().AddDate(0, 3, 0).Add(-time.Nanosecond)
} | go | {
"resource": ""
} |
q178897 | EndOfYear | test | func (now *Now) EndOfYear() time.Time {
return now.BeginningOfYear().AddDate(1, 0, 0).Add(-time.Nanosecond)
} | go | {
"resource": ""
} |
q178898 | MustParse | test | func (now *Now) MustParse(strs ...string) (t time.Time) {
t, err := now.Parse(strs...)
if err != nil {
panic(err)
}
return t
} | go | {
"resource": ""
} |
q178899 | Between | test | func (now *Now) Between(begin, end string) bool {
beginTime := now.MustParse(begin)
endTime := now.MustParse(end)
return now.After(beginTime) && now.Before(endTime)
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.