Skip to content

Instantly share code, notes, and snippets.

Cezar Sá Espinola cezarsa

View GitHub Profile
View import-clusters
#!/bin/bash
TSURU_TARGET=${TSURU_TARGET:-https://tsuru.globoi.com}
TSURU_TOKEN=${TSURU_TOKEN:-$(cat ~/.tsuru/token)}
target=$(sed "s|/$||g" <<<$TSURU_TARGET)
clusters="$(curl -sS -H"Authorization: bearer ${TSURU_TOKEN}" ${target}/provisioner/clusters)"
clusters_len=$(jq '. | length' <<<$clusters)
View terraform output
$ TF_LOG=trace terraform plan
2019/08/19 18:46:11 [INFO] Terraform version: 0.12.6
2019/08/19 18:46:11 [INFO] Go runtime version: go1.12.7
2019/08/19 18:46:11 [INFO] CLI args: []string{"/usr/local/bin/terraform", "plan"}
2019/08/19 18:46:11 [DEBUG] Attempting to open CLI config file: /Users/cezarsa/.terraformrc
2019/08/19 18:46:11 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/08/19 18:46:11 [INFO] CLI command args: []string{"plan"}
2019/08/19 18:46:11 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2019/08/19 18:46:11 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2019/08/19 18:46:11 [DEBUG] New state was assigned lineage "f206e877-0e66-9514-49b4-031d2e56c320"
View working_too_much.py
import os
from datetime import datetime, timedelta
import slack
import holidays
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')
SLACK_USER = os.environ.get('SLACK_USER')
from_date = datetime.strptime('2019-01-01', '%Y-%m-%d')
to_date = datetime.strptime('2019-06-18', '%Y-%m-%d')
View gist:1a0a3aefe602bd072974926a0073312e
package main
import (
"context"
"fmt"
"github.com/tsuru/rpaas-operator/pkg/apis"
"github.com/tsuru/rpaas-operator/pkg/apis/extensions/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
View gist:a919ddc198d509ea612518c2e05c984f
#!/bin/bash
trap 'echo "Done user data script."' EXIT
echo "Running user data script..."
sleep 30
View a.diff
diff --git a/provision/kubernetes/deploy.go b/provision/kubernetes/deploy.go
index 587eac2e0..f729c2682 100644
--- a/provision/kubernetes/deploy.go
+++ b/provision/kubernetes/deploy.go
@@ -455,8 +455,12 @@ func monitorDeployment(client *clusterClient, dep *v1beta1.Deployment, a provisi
fmt.Fprintf(w, " ---> %d of %d new units created\n", dep.Status.UpdatedReplicas, specReplicas)
}
if healthcheckTimeout == nil && dep.Status.UpdatedReplicas == specReplicas {
- healthcheckTimeout = time.After(maxWaitTimeDuration)
- fmt.Fprintf(w, " ---> waiting healthcheck on %d created units\n", specReplicas)
View test.go
func (s *S) TestRoundTripSNI(c *check.C) {
var receivedReq *http.Request
ts := httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
receivedReq = req
rw.Header().Set("X-Some-Rsp-Header", "rspvalue")
rw.WriteHeader(200)
rw.Write([]byte("my result"))
}))
defer ts.Close()
router := &recoderRouter{dst: ts.URL}
View nodecontainer.diff
diff --git a/provision/swarm/docker.go b/provision/swarm/docker.go
index 8d7b4eb..64b4bcf 100644
--- a/provision/swarm/docker.go
+++ b/provision/swarm/docker.go
@@ -601,7 +601,7 @@ func serviceSpecForNodeContainer(name, pool string) (*swarm.ServiceSpec, error)
return service, nil
}
-func upsertService(spec *swarm.ServiceSpec, client *docker.Client) (error, bool) {
+func upsertService(spec *swarm.ServiceSpec, client *docker.Client, placementOnly bool) (error, bool) {
View gist:d1ed0a2ae5d96b55094a21f2f302382b
https://github.com/go-errors/errors
https://github.com/palantir/stacktrace
https://github.com/ansel1/merry
https://github.com/go-errgo/errgo
https://github.com/amattn/deeperror
https://github.com/pkg/errors
https://github.com/hashicorp/errwrap
View mgo.go
package main
import (
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
func withUpsert(c *mgo.Collection) {
_, err := c.Upsert(bson.M{"_id": 1, "x": 2}, bson.M{"$set": bson.M{"x": 3}})
You can’t perform that action at this time.