Skip to content

Commit

Permalink
Merge pull request #959 from Vafilor/feat/create.namespace.stub
Browse files Browse the repository at this point in the history
feat: stub out create namespace
  • Loading branch information
Vafilor authored Oct 27, 2021
2 parents e991102 + 493ca51 commit 09b854a
Show file tree
Hide file tree
Showing 11 changed files with 540 additions and 16 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ FROM golang:1.15.5
COPY --from=builder /go/bin/core .
COPY --from=builder /go/src/db ./db
COPY --from=builder /go/bin/goose .
COPY --from=builder /go/src/manifest ./manifest

EXPOSE 8888
EXPOSE 8887
Expand Down
5 changes: 4 additions & 1 deletion api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Onepanel",
"description": "Onepanel API",
"version": "1.0.0",
"version": "1.0.2",
"contact": {
"name": "Onepanel project",
"url": "https:/onepanelio/core"
Expand Down Expand Up @@ -4184,6 +4184,9 @@
"properties": {
"name": {
"type": "string"
},
"sourceName": {
"type": "string"
}
}
},
Expand Down
16 changes: 13 additions & 3 deletions api/gen/namespace.pb.go

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

1 change: 1 addition & 0 deletions api/proto/namespace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ message CreateNamespaceRequest {

message Namespace {
string name = 1;
string sourceName = 2;
}
Empty file added manifest/.gitignore
Empty file.
7 changes: 7 additions & 0 deletions pkg/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (s SystemConfig) DatabaseDriverName() *string {
return s.GetValue("databaseDriverName")
}

// Provider gets the ONEPANEL_PROVIDER value, or nil.
func (s SystemConfig) Provider() *string {
return s.GetValue("ONEPANEL_PROVIDER")
}

// DatabaseConnection returns system config information to connect to a database
func (s SystemConfig) DatabaseConnection() (driverName, dataSourceName string) {
dataSourceName = fmt.Sprintf("host=%v user=%v password=%v dbname=%v sslmode=disable",
Expand Down Expand Up @@ -243,6 +248,7 @@ func (s SystemConfig) HMACKey() []byte {
// by the CLI. CLI will marshal this struct into the correct
// YAML structure for k8s configmap / secret.
type ArtifactRepositoryS3Provider struct {
Source string
KeyFormat string `yaml:"keyFormat"`
Bucket string
Endpoint string
Expand All @@ -260,6 +266,7 @@ type ArtifactRepositoryS3Provider struct {
// by the CLI. CLI will marshal this struct into the correct
// YAML structure for k8s configmap / secret.
type ArtifactRepositoryGCSProvider struct {
Source string
KeyFormat string `yaml:"keyFormat"`
Bucket string
Endpoint string
Expand Down
43 changes: 43 additions & 0 deletions pkg/istio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v1

import (
"fmt"
"github.com/onepanelio/core/pkg/util"
"google.golang.org/grpc/codes"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"strings"
)

const istioVirtualServiceResource = "VirtualServices"

func istioModelRestClient() (*rest.RESTClient, error) {
config := *NewConfig()
config.GroupVersion = &schema.GroupVersion{Group: "networking.istio.io", Version: "v1alpha3"}
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()

return rest.RESTClientFor(&config)
}

// CreateVirtualService creates an istio virtual service
func (c *Client) CreateVirtualService(namespace string, data interface{}) error {
restClient, err := istioModelRestClient()
if err != nil {
return err
}

err = restClient.Post().
Namespace(namespace).
Resource(istioVirtualServiceResource).
Body(data).
Do().
Error()

if err != nil && strings.Contains(err.Error(), "already exists") {
return util.NewUserError(codes.AlreadyExists, fmt.Sprintf("VirtualService already exists"))
}

return err
}
Loading

0 comments on commit 09b854a

Please sign in to comment.