Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #81 from keptn/release-0.2.1
Browse files Browse the repository at this point in the history
Release 0.2.1
  • Loading branch information
agrimmer authored Oct 1, 2019
2 parents 9a7a623 + a2b3b57 commit f5c220b
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 19 deletions.
25 changes: 13 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 38 additions & 5 deletions pkg/events/keptnEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package events

import "github.com/keptn/go-utils/pkg/models"

// ServiceCreateEventType is a CloudEvent type for creating new services
// ServiceCreateEventType is a CloudEvent type for creating a new service
const ServiceCreateEventType = "sh.keptn.event.service.create"

// InternalServiceCreateEventType is a CloudEvent type for creating new services
// InternalServiceCreateEventType is a CloudEvent type for creating a new service
const InternalServiceCreateEventType = "sh.keptn.internal.event.service.create"

// ProjectCreateEventType is a CloudEvent type for creating new projects
// ProjectCreateEventType is a CloudEvent type for creating a new project
const ProjectCreateEventType = "sh.keptn.event.project.create"

// InternalProjectCreateEventType is a CloudEvent type for creating new projects
// ProjectDeleteEventType is a CloudEvent type for deleting a project
const ProjectDeleteEventType = "sh.keptn.event.project.delete"

// InternalProjectCreateEventType is a CloudEvent type for creating a new project
const InternalProjectCreateEventType = "sh.keptn.internal.event.project.create"

// InternalProjectDeleteEventType is a CloudEvent type for deleting a project
const InternalProjectDeleteEventType = "sh.keptn.internal.event.project.delete"

// ConfigurationChangeEventType is a CloudEvent type for changing the configuration
const ConfigurationChangeEventType = "sh.keptn.event.configuration.change"

Expand All @@ -23,12 +29,27 @@ const ProblemOpenEventType = "sh.keptn.event.problem.open"
// ConfigureMonitoringEventType is a CloudEvent for configuring monitoring
const ConfigureMonitoringEventType = "sh.keptn.event.monitoring.configure"

// TestsFinishedEventType is a CloudEvent for indicating that tests have finished
const TestsFinishedEventType = "sh.keptn.event.tests.finished"

// ProjectCreateEventData represents the data for creating a new project
type ProjectCreateEventData struct {
// Project is the name of the project
Project string `json:"project"`
// Shipyard is a base64 encoded string of the shipyard file
Shipyard string `json:"shipyard"`
// GitUser is the name of a git user of an upstream repository
GitUser string `json:"gitUser,omitempty"`
// GitToken is the authentication token for the git user
GitToken string `json:"gitToken,omitempty"`
// GitRemoteURL is the remote url of a repository
GitRemoteURL string `json:"gitRemoteURL,omitempty"`
}

// ProjectDeleteEventData represents the data for deleting a new project
type ProjectDeleteEventData struct {
// Project is the name of the project
Project string `json:"project"`
}

// ServiceCreateEventData represents the data for creating a new service
Expand All @@ -43,7 +64,7 @@ type ServiceCreateEventData struct {
DeploymentStrategies map[string]DeploymentStrategy `json:"deploymentStrategies"`
}

// ConfigurationChangeEventData represents the data for
// ConfigurationChangeEventData represents the data for changing the service configuration
type ConfigurationChangeEventData struct {
// Project is the name of the project
Project string `json:"project"`
Expand All @@ -59,6 +80,18 @@ type ConfigurationChangeEventData struct {
DeploymentChanges []PropertyChange `json:"deploymentChanges,omitempty"`
}

// TestsFinishedEventData represents the data for a test finished event
type TestsFinishedEventData struct {
// Project is the name of the project
Project string `json:"project"`
// Service is the name of the new service
Service string `json:"service"`
// Stage is the name of the stage
Stage string `json:"stage"`
// TestStrategy is the testing strategy
TestStrategy string `json:"teststrategy"`
}

// PropertyChange describes the property to be changed
type PropertyChange struct {
PropertyPath string `json:"propertyPath"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/models/service_indicators.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ type ServiceIndicator struct {
Metric string `json:"metric" yaml:"metric"`
Source string `json:"source" yaml:"source"`
Query string `json:"query" yaml:"query"`
QueryObject []*ServiceIndicatorQueryObject `json:"queryObject" yaml:"queryObject"`
}

type ServiceIndicatorQueryObject struct {
Key string `json:"key" yaml:"key"`
Value string `json:"value" yaml:"value"`
}
36 changes: 36 additions & 0 deletions pkg/utils/configServiceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ func post(uri string, data []byte, c ConfigService) (*models.Error, error) {
return &respErr, nil
}

func delete(uri string, c ConfigService) (*models.Error, error) {

http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("DELETE", uri, nil)
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, c)

resp, err := c.getHTTPClient().Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return nil, nil
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var respErr models.Error
err = json.Unmarshal(body, &respErr)
if err != nil {
return nil, err
}

return &respErr, nil
}

func buildErrorResponse(errorStr string) *models.Error {
err := models.Error{Message: &errorStr}
return &err
}

func addAuthHeader(req *http.Request, c ConfigService) {
if c.getAuthHeader() != "" && c.getAuthToken() != "" {
req.Header.Set(c.getAuthHeader(), c.getAuthToken())
Expand Down
5 changes: 5 additions & 0 deletions pkg/utils/helmUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func LoadChart(data []byte) (*chart.Chart, error) {
return chartutil.LoadArchive(bytes.NewReader(data))
}

// LoadChartFromPath loads a directory or Helm chart into a Chart
func LoadChartFromPath(path string) (*chart.Chart, error) {
return chartutil.Load(path)
}

// PackageChart packages the chart and returns it
func PackageChart(ch *chart.Chart) ([]byte, error) {
helmPackage, err := ioutil.TempDir("", "")
Expand Down
27 changes: 27 additions & 0 deletions pkg/utils/kubeUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"k8s.io/client-go/util/retry"

appsv1 "k8s.io/api/apps/v1"
typesv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// Initialize all known client auth plugins.
_ "github.com/Azure/go-autorest/autorest"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -53,6 +55,31 @@ func RestartPodsWithSelector(useInClusterConfig bool, namespace string, selector
return nil
}

func WaitForPodsWithSelector(useInClusterConfig bool, namespace string, selector string,
retries int, waitingTime time.Duration) error {

clientset, err := GetKubeAPI(useInClusterConfig)
if err != nil {
return err
}

for i := 0; i < retries; i++ {
pods, err := clientset.Pods(namespace).List(metav1.ListOptions{LabelSelector: selector})
if err != nil {
return err
}
for _, pod := range pods.Items {
for _, cond := range pod.Status.Conditions {
if cond.Type != typesv1.PodReady {
time.Sleep(waitingTime)
break
}
}
}
}
return nil
}

func ScaleDeployment(useInClusterConfig bool, deployment string, namespace string, replicas int32) error {
clientset, err := GetClientset(useInClusterConfig)
if err != nil {
Expand Down
55 changes: 54 additions & 1 deletion pkg/utils/projectUtils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package utils

import (
"crypto/tls"
"encoding/json"
"io/ioutil"
"net/http"
"strings"

Expand Down Expand Up @@ -64,10 +66,61 @@ func (p *ProjectHandler) getHTTPClient() *http.Client {

// CreateProject creates a new project
func (p *ProjectHandler) CreateProject(project models.Project) (*models.Error, error) {

bodyStr, err := json.Marshal(project)
if err != nil {
return nil, err
}
return post(p.Scheme+"://"+p.getBaseURL()+"/v1/project", bodyStr, p)
}

// DeleteProject deletes a project
func (p *ProjectHandler) DeleteProject(project models.Project) (*models.Error, error) {
return delete(p.Scheme+"://"+p.getBaseURL()+"/v1/project/"+project.ProjectName, p)
}

// GetProject returns a project
func (p *ProjectHandler) GetProject(project models.Project) (*models.Project, *models.Error) {
return get(p.Scheme+"://"+p.getBaseURL()+"/v1/project/"+project.ProjectName, p)
}

func get(uri string, c ConfigService) (*models.Project, *models.Error) {

http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("GET", uri, nil)
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, c)

resp, err := c.getHTTPClient().Do(req)
if err != nil {
return nil, buildErrorResponse(err.Error())
}
defer resp.Body.Close()

if resp.StatusCode >= 200 && resp.StatusCode < 300 {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, buildErrorResponse(err.Error())
}

var respProject models.Project
err = json.Unmarshal(body, &respProject)
if err != nil {
return nil, buildErrorResponse(err.Error())
}

return &respProject, nil
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, buildErrorResponse(err.Error())
}

var respErr models.Error
err = json.Unmarshal(body, &respErr)
if err != nil {
return nil, buildErrorResponse(err.Error())
}

return nil, &respErr
}
8 changes: 8 additions & 0 deletions releasenotes/releasenotes_V0.2.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Release Notes 0.2.1

## New Features
- Add functions for deleting a project [#887](https://github.com/keptn/keptn/issues/887)

## Fixed Issues

## Known Limitations
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1

0 comments on commit f5c220b

Please sign in to comment.