Skip to content

Commit

Permalink
Merge pull request #37 from upmc-enterprises/enableCI
Browse files Browse the repository at this point in the history
Enabled ci / Cleanup
  • Loading branch information
stevesloka authored Feb 24, 2017
2 parents fe90009 + 99a68ca commit 265fa8b
Show file tree
Hide file tree
Showing 6,801 changed files with 3,288,902 additions and 454,363 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go

go:
- 1.8

sudo: required

services:
- docker

script:
- make test
- make build
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016, UPMC Enterprises
Copyright (c) 2017, UPMC Enterprises
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

.PHONY: all binary container push clean test

TAG = 1.5
TAG = 1.6
PREFIX = upmcenterprises

all: container

binary: main.go
build: main.go
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -o registry-creds --ldflags '-w' ./main.go

container: binary
container: build
docker build -t $(PREFIX)/registry-creds:$(TAG) .

push:
Expand All @@ -22,4 +22,4 @@ clean:
rm -f registry-creds

test: clean
go test $(go list ./... | grep -v /vendor/)
go test $(go list ./... | grep -v vendor)
8 changes: 4 additions & 4 deletions k8s/replicationController.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ metadata:
name: registry-creds
namespace: kube-system
labels:
version: v1.5
version: v1.6
spec:
replicas: 1
selector:
name: registry-creds
version: v1.5
version: v1.6
template:
metadata:
labels:
name: registry-creds
version: v1.5
version: v1.6
spec:
containers:
- image: upmcenterprises/registry-creds:1.5
- image: upmcenterprises/registry-creds:1.6
name: registry-creds
imagePullPolicy: Always
env:
Expand Down
146 changes: 146 additions & 0 deletions k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package k8sutil

import (
"github.com/Sirupsen/logrus"
"k8s.io/client-go/kubernetes"
coreType "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

// KubeInterface abstracts the k8s api
type KubeInterface interface {
Secrets(namespace string) coreType.SecretInterface
Namespaces() coreType.NamespaceInterface
ServiceAccounts(namespace string) coreType.ServiceAccountInterface
}

type K8sutilInterface struct {
Kclient KubeInterface
MasterHost string
}

// New creates a new instance of k8sutil
func New(kubeCfgFile, masterHost string) (*K8sutilInterface, error) {

client, err := newKubeClient(kubeCfgFile)

if err != nil {
logrus.Fatalf("Could not init Kubernetes client! [%s]", err)
}

k := &K8sutilInterface{
Kclient: client,
MasterHost: masterHost,
}

return k, nil
}

func newKubeClient(kubeCfgFile string) (KubeInterface, error) {

var client *kubernetes.Clientset

// Should we use in cluster or out of cluster config
if len(kubeCfgFile) == 0 {
logrus.Info("Using InCluster k8s config")
cfg, err := rest.InClusterConfig()

if err != nil {
return nil, err
}

client, err = kubernetes.NewForConfig(cfg)

if err != nil {
return nil, err
}
} else {
logrus.Infof("Using OutOfCluster k8s config with kubeConfigFile: %s", kubeCfgFile)
cfg, err := clientcmd.BuildConfigFromFlags("", kubeCfgFile)

if err != nil {
logrus.Error("Got error trying to create client: ", err)
return nil, err
}

client, err = kubernetes.NewForConfig(cfg)

if err != nil {
return nil, err
}
}

return client, nil
}

// GetNamespaces returns all namespaces
func (k *K8sutilInterface) GetNamespaces() (*v1.NamespaceList, error) {
namespaces, err := k.Kclient.Namespaces().List(v1.ListOptions{})
if err != nil {
logrus.Error("Error getting namespaces: ", err)
return nil, err
}

return namespaces, nil
}

// GetSecret get a secret
func (k *K8sutilInterface) GetSecret(namespace, secretname string) (*v1.Secret, error) {
secret, err := k.Kclient.Secrets(namespace).Get(secretname)
if err != nil {
logrus.Error("Error getting secret: ", err)
return nil, err
}

return secret, nil
}

// CreateSecret creates a secret
func (k *K8sutilInterface) CreateSecret(namespace string, secret *v1.Secret) error {
_, err := k.Kclient.Secrets(namespace).Create(secret)

if err != nil {
logrus.Error("Error creating secret: ", err)
return err
}

return nil
}

// UpdateSecret updates a secret
func (k *K8sutilInterface) UpdateSecret(namespace string, secret *v1.Secret) error {
_, err := k.Kclient.Secrets(namespace).Update(secret)

if err != nil {
logrus.Error("Error updating secret: ", err)
return err
}

return nil
}

// GetServiceAccount updates a secret
func (k *K8sutilInterface) GetServiceAccount(namespace, name string) (*v1.ServiceAccount, error) {
sa, err := k.Kclient.ServiceAccounts(namespace).Get(name)

if err != nil {
logrus.Error("Error getting service account: ", err)
return nil, err
}

return sa, nil
}

// UpdateServiceAccount updates a secret
func (k *K8sutilInterface) UpdateServiceAccount(namespace string, sa *v1.ServiceAccount) error {
_, err := k.Kclient.ServiceAccounts(namespace).Update(sa)

if err != nil {
logrus.Error("Error updating service account: ", err)
return err
}

return nil
}
Loading

0 comments on commit 265fa8b

Please sign in to comment.