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

chore: create ws for each namespace #3

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
100 changes: 60 additions & 40 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package main

import (
"context"
"net/http"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
core "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"

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

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

crt "github.com/codeready-toolchain/api/api/v1alpha1"
)

Expand All @@ -24,6 +32,14 @@ type Signup struct {
SignupStatus SignupStatus `json:"status"`
}

var (
scheme = runtime.NewScheme()
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
}

func main() {
e := echo.New()

Expand All @@ -47,53 +63,57 @@ func main() {
return c.JSON(http.StatusOK, resp)
})

cfg, err := config.GetConfig()
if err != nil {
e.Logger.Fatal(err)
}

cl, err := client.New(cfg, client.Options{Scheme: scheme})
if err != nil {
e.Logger.Fatal(err)
}
namespaceList := &core.NamespaceList{}
err = cl.List(
context.Background(),
namespaceList,
)
if err != nil {
e.Logger.Fatal(err)
}

gv := crt.GroupVersion.String()

workspaces := crt.WorkspaceList{
TypeMeta: metav1.TypeMeta{
Kind: "WorkspaceList",
APIVersion: gv,
},
Items: []crt.Workspace{
{
TypeMeta: metav1.TypeMeta{
Kind: "Workspace",
APIVersion: gv,
},
ObjectMeta: metav1.ObjectMeta{
Name: "user-ns1",
},
Status: crt.WorkspaceStatus{
Namespaces: []crt.SpaceNamespace{
{
Name: "user-ns1",
Type: "default",
},
},
Owner: "user1",
Role: "admin",
},
var wss []crt.Workspace

for _, ns := range namespaceList.Items {
ws := crt.Workspace{
TypeMeta: metav1.TypeMeta{
Kind: "Workspace",
APIVersion: gv,
},
{
TypeMeta: metav1.TypeMeta{
Kind: "Workspace",
APIVersion: gv,
},
ObjectMeta: metav1.ObjectMeta{
Name: "user-ns2",
},
Status: crt.WorkspaceStatus{
Namespaces: []crt.SpaceNamespace{
{
Name: "user-ns2",
Type: "default",
},
ObjectMeta: metav1.ObjectMeta{
Name: ns.Name,
},
Status: crt.WorkspaceStatus{
Namespaces: []crt.SpaceNamespace{
{
Name: ns.Name,
Type: "default",
},
Owner: "user1",
Role: "admin",
},
// Owner: "user1",
// Role: "admin",
},
}
wss = append(wss, ws)
}

workspaces := crt.WorkspaceList{
TypeMeta: metav1.TypeMeta{
Kind: "WorkspaceList",
APIVersion: gv,
},
Items: wss,
}

e.GET("/workspaces", func(c echo.Context) error {
Expand Down
15 changes: 13 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ go 1.20
require (
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9
github.com/labstack/echo/v4 v4.11.4
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v0.25.0
sigs.k8s.io/controller-runtime v0.13.0
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand All @@ -21,6 +26,7 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.4.2 // indirect
Expand All @@ -29,23 +35,28 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openshift/api v0.0.0-20230213134911-7ba313770556 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.25.0 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/controller-runtime v0.13.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading
Loading