Skip to content

Commit

Permalink
Merge pull request #30 from hasura/godocs
Browse files Browse the repository at this point in the history
added docs
  • Loading branch information
shahidhk committed Mar 16, 2018
2 parents 9073037 + 2f69c95 commit e825de1
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
44 changes: 34 additions & 10 deletions pkg/apis/gitkube.sh/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

//Remote
// Remote is the definition of a remote
type Remote struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -18,39 +18,63 @@ type Remote struct {
}

type RemoteSpec struct {
AuthorizedKeys []string `json:"authorizedKeys"`
Registry RegistrySpec `json:"registry"`
Deployments []DeploymentSpec `json:"deployments"`
// SSH public keys for git push authorization
AuthorizedKeys []string `json:"authorizedKeys"`

// Registry details for pushing and pulling from external registry
// +optional
Registry RegistrySpec `json:"registry"`

// List of deployment spec.
// Deployment spec defines which deployments are under gitkube management
Deployments []DeploymentSpec `json:"deployments"`
}

type RemoteStatus struct {
RemoteUrl string `json:"remoteUrl"`
// Url of the git remote where the repo is pushed
RemoteUrl string `json:"remoteUrl"`

// Description of RemoteUrl
// Contains error description if RemoteUrl is not available
RemoteUrlDesc string `json:"remoteUrlDesc"`
}

type RegistrySpec struct {
Url string `json:"url,omitempty"`
// Url of the external registry where built images should be pushed
// E.g. registry.harbor.io/library
Url string `json:"url,omitempty"`

// Credentials for registry
Credentials CredentialsSpec `json:"credentials,omitempty"`
}

type CredentialsSpec struct {
// Secret should point to a secret of type docker-registry
SecretKeyRef corev1.SecretKeySelector `json:"secretKeyRef,omitempty"`
}

type DeploymentSpec struct {
Name string `json:"name"`
// Name of the deployment
Name string `json:"name"`

// List of container spec which are part of the deployment
Containers []ContainerSpec `json:"containers"`
}

type ContainerSpec struct {
Name string `json:"name"`
Path string `json:"path"`
// Name of container
Name string `json:"name"`

// Location of source code in the git repo for the container
Path string `json:"path"`

// Location of dockerfile for the container
Dockerfile string `json:"dockerfile"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

//RemoteList
// RemoteList is a list of Remotes
type RemoteList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
listers "github.com/hasura/gitkube/pkg/client/listers/gitkube/v1alpha1"
)

// RestartDeployment takes a deployment and annotates the pod spec with current timestamp
// This causes a fresh rollout of the deployment
func RestartDeployment(kubeclientset *kubernetes.Clientset, deployment *v1beta1.Deployment) error {

timeannotation := fmt.Sprintf("%v", time.Now().Unix())
Expand All @@ -32,6 +34,7 @@ func RestartDeployment(kubeclientset *kubernetes.Clientset, deployment *v1beta1.
return nil
}

// CreateGitkubeConf takes a list of remotes, reshapes it and marshals it into a string
func CreateGitkubeConf(kubeclientset *kubernetes.Clientset, remotelister listers.RemoteLister) string {
remotes, err := remotelister.List(labels.Everything())
if err != nil {
Expand All @@ -53,6 +56,7 @@ func CreateGitkubeConf(kubeclientset *kubernetes.Clientset, remotelister listers

}

// CreateRemoteJson takes a remote and reshapes it
func CreateRemoteJson(kubeclientset *kubernetes.Clientset, remote *v1alpha1.Remote) interface{} {
remoteMap := make(map[string]interface{})
deploymentsMap := make(map[string]interface{})
Expand All @@ -70,14 +74,15 @@ func CreateRemoteJson(kubeclientset *kubernetes.Clientset, remote *v1alpha1.Remo
}

remoteMap["authorized-keys"] = strings.Join(remote.Spec.AuthorizedKeys, "\n")
remoteMap["registry"] = CreateRegistryJson(kubeclientset, remote)
remoteMap["registry"] = createRegistryJson(kubeclientset, remote)
remoteMap["deployments"] = deploymentsMap

return remoteMap

}

func CreateRegistryJson(kubeclientset *kubernetes.Clientset, remote *v1alpha1.Remote) interface{} {
// createRegistryJson takes a remote and returns a reshaped map of its registry
func createRegistryJson(kubeclientset *kubernetes.Clientset, remote *v1alpha1.Remote) interface{} {
registry := remote.Spec.Registry
registryMap := make(map[string]interface{})

Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type GitController struct {
configmapworkqueue workqueue.RateLimitingInterface
}

// NewController returns a GitController
func NewController(
kubeclientset *kubernetes.Clientset,
clientset *clientset.Clientset,
Expand Down Expand Up @@ -144,6 +145,7 @@ func NewController(
return controller
}

// Run starts the worker threads for remote and configmap work queues
func (c *GitController) Run(stopCh <-chan struct{}) error {
defer runtime.HandleCrash()
defer c.remoteworkqueue.ShutDown()
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *GitController) syncRemoteHandler(key string) error {

ciconf, err := c.configmapsLister.ConfigMaps(gitkubeNamespace).Get(gitkubeConfigMapName)
if err != nil {
//create config map
//create config map?
return err
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/util/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"k8s.io/client-go/kubernetes"
)

// GetExternalIP gets the name or IP of (gitkubed) service
// Returns error for unsupported Service types
func GetExternalIP(kubeclientset *kubernetes.Clientset, service *corev1.Service) (string, error) {
switch service.Spec.Type {
case corev1.ServiceTypeClusterIP:
Expand Down Expand Up @@ -38,6 +40,7 @@ func GetExternalIP(kubeclientset *kubernetes.Clientset, service *corev1.Service)

}

// GetLoadBalancerIPOrName gets the name or IP from LoadBalancerIngress resource
func GetLoadBalancerIPOrName(ingress corev1.LoadBalancerIngress) string {
if ingress.IP != "" {
return ingress.IP
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
)

// GetMD5Hash takes a string and returns its MD5 hash
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
Expand Down

0 comments on commit e825de1

Please sign in to comment.