Make subscriptions Kubernetes-ready.
Update our .hgignore file to include the docker-ready subscripionsd binary
(which differs from the local subscriptionsd binary only in that it's
statically-compiled for linux).
Add a replication controller for subscriptionsd that will spin up the
appropriate pods for us and make sure our Stripe and Subscriptionsd secret
volumes are attached, so the pods may configure themselves with that private
info.
Create a Stripe secret volume with a placeholder for the stripe secret key.
Create a Subscriptionsd secret volume with the DSN sent to the base64 encoding
of an empty string right now (which means subscriptionsd will store data in
memory, but whatever.)
Create a subscriptionsd service that will route traffic to the subscriptionsd
pods created by the replication controller.
Create a minimal Dockerfile to get the subscriptionsd binary running on
kubernetes.
Add a build-docker helper script that will compile a Docker-ready subscriptionsd
binary (by compiling it in a Docker container).
Copy a Ubuntu ca-certificates.crt file that we'll inject into our Dockerfile so
the Stripe SSL can be resolved. Busybox doesn't have any certificates, by
default.
Create a wrapper script that will be run in the Docker container to read the
secrets from our secret volumes and inject them as environment variables, which
is what subscriptionsd understands.
4 "code.secondbit.org/uuid.hg"
7 func stripeSubscriptionInMemstore(stripeSubscription string, m *Memstore) bool {
8 for _, sub := range m.subscriptions {
9 if sub.StripeSubscription == stripeSubscription {
16 func (m *Memstore) CreateSubscription(sub Subscription) error {
17 m.subscriptionLock.Lock()
18 defer m.subscriptionLock.Unlock()
20 if _, ok := m.subscriptions[sub.UserID.String()]; ok {
21 return ErrSubscriptionAlreadyExists
23 if stripeSubscriptionInMemstore(sub.StripeSubscription, m) {
24 return ErrStripeSubscriptionAlreadyExists
26 m.subscriptions[sub.UserID.String()] = sub
30 func (m *Memstore) UpdateSubscription(id uuid.ID, change SubscriptionChange) error {
32 return ErrSubscriptionChangeEmpty
35 m.subscriptionLock.Lock()
36 defer m.subscriptionLock.Unlock()
38 s, ok := m.subscriptions[id.String()]
40 return ErrSubscriptionNotFound
42 if change.StripeSubscription != nil {
43 if stripeSubscriptionInMemstore(*change.StripeSubscription, m) {
44 return ErrStripeSubscriptionAlreadyExists
48 m.subscriptions[id.String()] = s
52 func (m *Memstore) DeleteSubscription(id uuid.ID) error {
53 m.subscriptionLock.Lock()
54 defer m.subscriptionLock.Unlock()
56 _, ok := m.subscriptions[id.String()]
58 return ErrSubscriptionNotFound
60 delete(m.subscriptions, id.String())
64 func (m *Memstore) GetSubscriptions(ids []uuid.ID) (map[string]Subscription, error) {
66 return map[string]Subscription{}, ErrNoSubscriptionID
68 m.subscriptionLock.RLock()
69 defer m.subscriptionLock.RUnlock()
71 result := map[string]Subscription{}
73 for _, id := range ids {
74 s, ok := m.subscriptions[id.String()]
78 result[s.UserID.String()] = s
83 func (m *Memstore) GetSubscriptionStats() (SubscriptionStats, error) {
84 m.subscriptionLock.RLock()
85 defer m.subscriptionLock.RUnlock()
87 stats := SubscriptionStats{
88 Plans: map[string]int64{},
91 for _, subscription := range m.subscriptions {
93 stats.Plans[subscription.Plan]++
95 if subscription.Canceling {
98 if subscription.Status == "past_due" || subscription.Status == "unpaid" {