Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAY-85] Add AppId to applications #276

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
cluster-name: "test-cluster-1"
args: --agents 1
- name: Install Integration Test Dependencies
- name: Install Test Dependencies
run: |
# kubebuilder
make install-kubebuilder KUBEBUILDER_INSTALL_DIR=/tmp/kubebuilder/bin
Expand All @@ -29,6 +29,7 @@ jobs:
chmod a+x /tmp/kubebuilder/bin/kube-apiserver
cp /tmp/kubebuilder/bin/kube-apiserver /usr/local/bin/kube-apiserver
export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver
export KUBEBUILDER_ASSETS=/tmp/kubebuilder/bin/

# etcd
curl -L -o /tmp/etcd-v3.5.4-linux-amd64.tar.gz https://github.com/etcd-io/etcd/releases/download/v3.5.4/etcd-v3.5.4-linux-amd64.tar.gz
Expand Down Expand Up @@ -78,7 +79,15 @@ jobs:
# install bats
sudo apt-get update -yq && sudo apt-get install bats -y
- name: Unit Tests
run: make test
run: |
TEST_ASSET_ETCD="/tmp/kubebuilder/bin/etcd" \
TEST_ASSET_KUBE_APISERVER="/tmp/kubebuilder/bin/kube-apiserver" \
KUBEBUILDER_ASSETS="/tmp/kubebuilder/bin/" \
go test ./... -p 1
TEST_ASSET_ETCD="/tmp/kubebuilder/bin/etcd" \
TEST_ASSET_KUBE_APISERVER="/tmp/kubebuilder/bin/kube-apiserver" \
KUBEBUILDER_ASSETS="/tmp/kubebuilder/bin/" \
go test ./... -p 1 -coverprofile cover.out | tee coverage.txt
- name: Checkout unit-test-coverage
uses: actions/checkout@v2
with:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ GOARCH=$(shell go env GOARCH)
KUBEBUILDER_VERSION=3.5.0
KUBEBUILDER_INSTALL_DIR ?= "/usr/local/kubebuilder/bin"
KUBEBUILDER_RELEASE=kubebuilder_${GOOS}_${GOARCH}
KUBEBUILDER_ASSETS ?= "/usr/local/kubebuilder/bin"
TEST_ASSET_KUBE_APISERVER= ?= "/usr/local/kubebuilder/bin/kube-apiserver"

KUSTOMIZE ?= $(shell which kustomize)
KUSTOMIZE_INSTALL_DIR ?= "/usr/local/bin"
Expand All @@ -27,7 +29,8 @@ all: manager ketch
# Run tests
.PHONY: test
test: generate fmt vet manifests
go test ./... -coverprofile cover.out | tee coverage.txt
go test ./... -p 1
go test ./... -p 1 -coverprofile cover.out | tee coverage.txt

# Build manager binary
.PHONY: manager
Expand Down
2 changes: 1 addition & 1 deletion ci/limits.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"github.com/theketchio/ketch/cmd/ketch": 59.7,
"github.com/theketchio/ketch/cmd/ketch": 59.2,
"github.com/theketchio/ketch/cmd/ketch/configuration": 0,
"github.com/theketchio/ketch/cmd/ketch/output": 68.3,
"github.com/theketchio/ketch/cmd/manager": 0,
Expand Down
1 change: 1 addition & 0 deletions cmd/ketch/app_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ func TestNewCommand(t *testing.T) {

if tc.setup != nil {
tc.setup(t)

}
cmd := newAppDeployCmd(nil, tc.params, tc.userDefault)
cmd.SetArgs(tc.arguments)
Expand Down
7 changes: 5 additions & 2 deletions cmd/ketch/app_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Test_appExport(t *testing.T) {
Name: "dashboard",
},
Spec: ketchv1.AppSpec{
ID: "id",
Namespace: "mynamespace",
Ingress: ketchv1.IngressSpec{
GenerateDefaultCname: true,
Expand Down Expand Up @@ -106,7 +107,8 @@ func Test_appExport(t *testing.T) {
appName: "dashboard",
filename: "app.yaml",
},
wantOut: `name: dashboard
wantOut: `id: id
name: dashboard
namespace: mynamespace
type: Application
version: v1
Expand All @@ -126,7 +128,8 @@ version: v1
options: appExportOptions{
appName: "dashboard",
},
wantOut: `name: dashboard
wantOut: `id: id
name: dashboard
namespace: mynamespace
type: Application
version: v1
Expand Down
2 changes: 1 addition & 1 deletion cmd/ketch/app_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func appInfo(ctx context.Context, cfg config, options appInfoOptions, out io.Wri
}

appPods, err := cfg.KubernetesClient().CoreV1().Pods(app.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf(`%s=%s`, utils.KetchAppNameLabel, app.Name),
LabelSelector: fmt.Sprintf(`%s=%s`, utils.KetchAppNameLabel, app.AppName()),
})
if err != nil {
return err
Expand Down
17 changes: 11 additions & 6 deletions cmd/ketch/app_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func appList(ctx context.Context, cfg config, out io.Writer) error {
func generateAppListOutput(apps ketchv1.AppList, allPods *corev1.PodList) []appListOutput {
var outputs []appListOutput
for _, item := range apps.Items {
pods := filterAppPods(item.Name, allPods.Items)
pods := filterAppPods(item.ID(), item.AppName(), allPods.Items)
urls := strings.Join(item.CNames(), " ")
outputs = append(outputs, appListOutput{
Name: item.Name,
Name: item.AppName(),
Namespace: item.Spec.Namespace,
State: appState(pods),
Addresses: urls,
Expand Down Expand Up @@ -92,12 +92,17 @@ func allAppsPods(ctx context.Context, cfg config, apps []ketchv1.App) (*corev1.P
})
}

func filterAppPods(appName string, pods []corev1.Pod) []corev1.Pod {
func filterAppPods(appId string, appName string, pods []corev1.Pod) []corev1.Pod {
var appPods []corev1.Pod
for _, pod := range pods {
if pod.Labels[utils.KetchAppNameLabel] == appName {
appPods = append(appPods, pod)
}
if len(appId) > 0 {
if pod.Labels[utils.KetchAppIdLabel] == appId {
appPods = append(appPods, pod)
}
}
}
return appPods
}
Expand All @@ -111,12 +116,12 @@ func appListNames(cfg config, nameFilter ...string) ([]string, error) {
appNames := make([]string, 0)
for _, a := range apps.Items {
if len(nameFilter) == 0 {
appNames = append(appNames, a.Name)
appNames = append(appNames, a.AppName())
}

for _, filter := range nameFilter {
if strings.Contains(a.Name, filter) {
appNames = append(appNames, a.Name)
if strings.Contains(a.AppName(), filter) {
appNames = append(appNames, a.AppName())
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/ketch/app_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func newAppLogCmd(cfg config, out io.Writer, appLog appLogFn) *cobra.Command {
}

type appLogOptions struct {
appId string
appName string
processName string
deploymentVersion int
Expand All @@ -79,6 +80,9 @@ func appLog(ctx context.Context, cfg config, options appLogOptions, out io.Write
set := map[string]string{
utils.KetchAppNameLabel: options.appName,
}
if len(options.appId) > 0 {
set[utils.KetchAppIdLabel] = options.appId
}
if len(options.processName) > 0 {
set[utils.KetchProcessNameLabel] = options.processName
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ketch/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Read(path string) KetchConfig {
return ketchConfig
}

//Write writes the provided KetchConfig to the given path. In the event the path is not found it will be created
// Write writes the provided KetchConfig to the given path. In the event the path is not found it will be created
func Write(ketchConfig KetchConfig, path string) error {
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/ketch/job_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ description: test`,
require.Equal(t, tt.wantOut, out.String())

gotJob := ketchv1.Job{}
err = tt.cfg.Client().Get(context.Background(), types.NamespacedName{Name: tt.jobName}, &gotJob)
err = tt.cfg.Client().Get(context.Background(), types.NamespacedName{Name: tt.jobName, Namespace: "default"}, &gotJob)
require.Nil(t, err)
require.Equal(t, tt.wantJobSpec, gotJob.Spec)
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/ketch/job_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestJobExport(t *testing.T) {
mockJob := &ketchv1.Job{
ObjectMeta: metav1.ObjectMeta{Name: "hello"},
ObjectMeta: metav1.ObjectMeta{Name: "hello", Namespace: "default"},
Spec: ketchv1.JobSpec{
Name: "hello",
Version: "v1",
Expand Down
4 changes: 2 additions & 2 deletions cmd/ketch/job_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (

func TestJobRemove(t *testing.T) {
mockJob := &ketchv1.Job{
ObjectMeta: metav1.ObjectMeta{Name: "hello"},
ObjectMeta: metav1.ObjectMeta{Name: "hello", Namespace: "default"},
Spec: ketchv1.JobSpec{
Name: "hello",
Version: "v1",
Namespace: "mynamespace",
Namespace: "default",
Description: "test",
Parallelism: 1,
Completions: 1,
Expand Down
Loading