Skip to content

Commit 09b854a

Browse files
authored
Merge pull request #959 from Vafilor/feat/create.namespace.stub
feat: stub out create namespace
2 parents e991102 + 493ca51 commit 09b854a

File tree

11 files changed

+540
-16
lines changed

11 files changed

+540
-16
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ FROM golang:1.15.5
1212
COPY --from=builder /go/bin/core .
1313
COPY --from=builder /go/src/db ./db
1414
COPY --from=builder /go/bin/goose .
15+
COPY --from=builder /go/src/manifest ./manifest
1516

1617
EXPOSE 8888
1718
EXPOSE 8887

api/api.swagger.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "Onepanel",
55
"description": "Onepanel API",
6-
"version": "1.0.0",
6+
"version": "1.0.2",
77
"contact": {
88
"name": "Onepanel project",
99
"url": "https://github.com/onepanelio/core"
@@ -4184,6 +4184,9 @@
41844184
"properties": {
41854185
"name": {
41864186
"type": "string"
4187+
},
4188+
"sourceName": {
4189+
"type": "string"
41874190
}
41884191
}
41894192
},

api/gen/namespace.pb.go

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proto/namespace.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ message CreateNamespaceRequest {
4040

4141
message Namespace {
4242
string name = 1;
43+
string sourceName = 2;
4344
}

manifest/.gitignore

Whitespace-only changes.

pkg/config_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ func (s SystemConfig) DatabaseDriverName() *string {
174174
return s.GetValue("databaseDriverName")
175175
}
176176

177+
// Provider gets the ONEPANEL_PROVIDER value, or nil.
178+
func (s SystemConfig) Provider() *string {
179+
return s.GetValue("ONEPANEL_PROVIDER")
180+
}
181+
177182
// DatabaseConnection returns system config information to connect to a database
178183
func (s SystemConfig) DatabaseConnection() (driverName, dataSourceName string) {
179184
dataSourceName = fmt.Sprintf("host=%v user=%v password=%v dbname=%v sslmode=disable",
@@ -243,6 +248,7 @@ func (s SystemConfig) HMACKey() []byte {
243248
// by the CLI. CLI will marshal this struct into the correct
244249
// YAML structure for k8s configmap / secret.
245250
type ArtifactRepositoryS3Provider struct {
251+
Source string
246252
KeyFormat string `yaml:"keyFormat"`
247253
Bucket string
248254
Endpoint string
@@ -260,6 +266,7 @@ type ArtifactRepositoryS3Provider struct {
260266
// by the CLI. CLI will marshal this struct into the correct
261267
// YAML structure for k8s configmap / secret.
262268
type ArtifactRepositoryGCSProvider struct {
269+
Source string
263270
KeyFormat string `yaml:"keyFormat"`
264271
Bucket string
265272
Endpoint string

pkg/istio.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package v1
2+
3+
import (
4+
"fmt"
5+
"github.com/onepanelio/core/pkg/util"
6+
"google.golang.org/grpc/codes"
7+
"k8s.io/apimachinery/pkg/runtime/schema"
8+
"k8s.io/client-go/kubernetes/scheme"
9+
"k8s.io/client-go/rest"
10+
"strings"
11+
)
12+
13+
const istioVirtualServiceResource = "VirtualServices"
14+
15+
func istioModelRestClient() (*rest.RESTClient, error) {
16+
config := *NewConfig()
17+
config.GroupVersion = &schema.GroupVersion{Group: "networking.istio.io", Version: "v1alpha3"}
18+
config.APIPath = "/apis"
19+
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
20+
21+
return rest.RESTClientFor(&config)
22+
}
23+
24+
// CreateVirtualService creates an istio virtual service
25+
func (c *Client) CreateVirtualService(namespace string, data interface{}) error {
26+
restClient, err := istioModelRestClient()
27+
if err != nil {
28+
return err
29+
}
30+
31+
err = restClient.Post().
32+
Namespace(namespace).
33+
Resource(istioVirtualServiceResource).
34+
Body(data).
35+
Do().
36+
Error()
37+
38+
if err != nil && strings.Contains(err.Error(), "already exists") {
39+
return util.NewUserError(codes.AlreadyExists, fmt.Sprintf("VirtualService already exists"))
40+
}
41+
42+
return err
43+
}

0 commit comments

Comments
 (0)