Skip to content

Commit

Permalink
init apps modules #14 #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Apr 19, 2020
1 parent 8d83e69 commit 5506e56
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/app/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func Cluster(c *gin.Context) {
}).Error(fmt.Sprintf(`Error: %s`, err.Error()))
}

cluster.GetDeployments(context.Background(), "default", "app.clivern.com/managed-by=beetle")

result.Name = cluster.Name
result.Health = status

Expand Down
42 changes: 40 additions & 2 deletions internal/app/kubernetes/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,48 @@
package kubernetes

import (
"fmt"
"context"

"github.com/clivern/beetle/internal/app/model"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GetApplicationVersion gets current application version
func (c *Cluster) GetApplicationVersion(ctx context.Context, namespace, appID, imageFormat string) (string, error) {
return appID, nil
func (c *Cluster) GetApplicationVersion(ctx context.Context, namespace, id, format string) (string, error) {
err := c.Config()

if err != nil {
return id, err
}

data, err := c.ClientSet.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf(
"%s=%s,%s=%s",
"app.clivern.com/managed-by",
"beetle",
"app.clivern.com/application-id",
id,
),
})

if err != nil {
return id, err
}

for _, deployment := range data.Items {
fmt.Printf("%+v\n", deployment.Spec.Template.Spec.Containers)



result = append(result, model.Deployment{
Name: deployment.ObjectMeta.Name,
UID: string(deployment.ObjectMeta.UID),
})
}

return result, nil

return id, nil
}
6 changes: 5 additions & 1 deletion internal/app/kubernetes/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package kubernetes

import (
"fmt"
"context"

"github.com/clivern/beetle/internal/app/model"
Expand All @@ -13,7 +14,7 @@ import (
)

// GetDeployments gets a list of deployments
func (c *Cluster) GetDeployments(ctx context.Context, namespace string, label string) ([]model.Deployment, error) {
func (c *Cluster) GetDeployments(ctx context.Context, namespace, label string) ([]model.Deployment, error) {
result := []model.Deployment{}

err := c.Config()
Expand All @@ -31,8 +32,10 @@ func (c *Cluster) GetDeployments(ctx context.Context, namespace string, label st
}

for _, deployment := range data.Items {
fmt.Printf("%+v\n", deployment.Spec.Template.Spec.Containers)
result = append(result, model.Deployment{
Name: deployment.ObjectMeta.Name,
UID: string(deployment.ObjectMeta.UID),
})
}

Expand All @@ -56,6 +59,7 @@ func (c *Cluster) GetDeployment(ctx context.Context, namespace, name string) (mo
}

result.Name = deployment.ObjectMeta.Name
result.UID = string(deployment.ObjectMeta.UID)

return result, nil
}
1 change: 1 addition & 0 deletions internal/app/model/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Application struct {
Name string `yaml:"name"`
ImageFormat string `yaml:"imageFormat"`
CurrentImage string `yaml:"currentImage"`
Deployment []Deployment `yaml:"deployment"`
}

// Configs struct
Expand Down
1 change: 1 addition & 0 deletions internal/app/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Deployment struct
type Deployment struct {
Name string `json:"name"`
UID string `json:"uid"`
}

// LoadFromJSON update object from json
Expand Down

0 comments on commit 5506e56

Please sign in to comment.