Skip to content

Commit

Permalink
restructure: segment code base in different packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ramantehlan committed Jun 5, 2024
1 parent 51970f1 commit 28de9b0
Show file tree
Hide file tree
Showing 38 changed files with 458 additions and 441 deletions.
4 changes: 2 additions & 2 deletions charts/elasti/templates/elastiservice-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: elastiservices.elasti.truefoundry.io
name: elastiservices.elasti.truefoundry.com
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
labels:
{{- include "elasti.labels" . | nindent 4 }}
spec:
group: elasti.truefoundry.io
group: elasti.truefoundry.com
names:
kind: ElastiService
listKind: ElastiServiceList
Expand Down
4 changes: 2 additions & 2 deletions charts/elasti/templates/elastiservice-editor-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- include "elasti.labels" . | nindent 4 }}
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
Expand All @@ -18,7 +18,7 @@ rules:
- update
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions charts/elasti/templates/elastiservice-viewer-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ metadata:
{{- include "elasti.labels" . | nindent 4 }}
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
- get
- list
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
6 changes: 3 additions & 3 deletions charts/elasti/templates/manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- include "elasti.labels" . | nindent 4 }}
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
Expand All @@ -18,13 +18,13 @@ rules:
- update
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/finalizers
verbs:
- update
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
9 changes: 9 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVWCNtNq/ewIX7HIKnELmEx2nDP42yskD/pi7QE=
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465/go.mod h1:gx7rwoVhcfuVKG5uya9Hs3Sxj7EIvldVofAWIUtGouw=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jba/printsrc v0.2.2/go.mod h1:1xULjw59sL0dPdWpDoVU06TIEO/Wnfv6AHRpiElTwYM=
Expand Down Expand Up @@ -214,6 +215,7 @@ github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ai
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE=
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down Expand Up @@ -269,17 +271,22 @@ go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -289,7 +296,9 @@ golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240208230135-b75ee8823808/go.mod h1:KG1lNk5ZFNssSZLrpVb4sMXKMpGwGXOxSG3rnu2gZQQ=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
Expand Down
2 changes: 1 addition & 1 deletion operator/api/v1alpha1/elastiservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
ElastiServiceFinalizer = "elasti.truefoundry.io/finalizer"
ElastiServiceFinalizer = "elasti.truefoundry.com/finalizer"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down
4 changes: 2 additions & 2 deletions operator/api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

// Package v1alpha1 contains API Schema definitions for the elasti v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=elasti.truefoundry.io
// +groupName=elasti.truefoundry.com
package v1alpha1

import (
Expand All @@ -26,7 +26,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "elasti.truefoundry.io", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "elasti.truefoundry.com", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: elastiservices.elasti.truefoundry.io
name: elastiservices.elasti.truefoundry.com
spec:
group: elasti.truefoundry.io
group: elasti.truefoundry.com
names:
kind: ElastiService
listKind: ElastiServiceList
Expand Down
2 changes: 1 addition & 1 deletion operator/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/elasti.truefoundry.io_elastiservices.yaml
- bases/elasti.truefoundry.com_elastiservices.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
Expand Down
4 changes: 2 additions & 2 deletions operator/config/rbac/elastiservice_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
name: elastiservice-editor-role
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
Expand All @@ -20,7 +20,7 @@ rules:
- update
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
4 changes: 2 additions & 2 deletions operator/config/rbac/elastiservice_viewer_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ metadata:
name: elastiservice-viewer-role
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
- get
- list
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
6 changes: 3 additions & 3 deletions operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: manager-role
rules:
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices
verbs:
Expand All @@ -17,13 +17,13 @@ rules:
- update
- watch
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/finalizers
verbs:
- update
- apiGroups:
- elasti.truefoundry.io
- elasti.truefoundry.com
resources:
- elastiservices/status
verbs:
Expand Down
2 changes: 1 addition & 1 deletion operator/config/samples/elasti_v1alpha1_elastiservice.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: elasti.truefoundry.io/v1alpha1
apiVersion: elasti.truefoundry.com/v1alpha1
kind: ElastiService
metadata:
labels:
Expand Down
6 changes: 3 additions & 3 deletions operator/internal/controller/elastiservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func getMutexForRequest(key string) *sync.Mutex {
return l.(*sync.Mutex)
}

//+kubebuilder:rbac:groups=elasti.truefoundry.io,resources=elastiservices,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=elasti.truefoundry.io,resources=elastiservices/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=elasti.truefoundry.io,resources=elastiservices/finalizers,verbs=update
//+kubebuilder:rbac:groups=elasti.truefoundry.com,resources=elastiservices,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=elasti.truefoundry.com,resources=elastiservices/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=elasti.truefoundry.com,resources=elastiservices/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
Expand Down
26 changes: 26 additions & 0 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package logger

import (
"os"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func GetLogger(env string) (logger *zap.Logger, err error) {
if env == "prod" {
logger, err = zap.NewProduction()
if err != nil {
return nil, err
}
} else {
encoderConfig := zap.NewDevelopmentEncoderConfig()
encoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
encoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
encoderConfig.EncodeDuration = zapcore.StringDurationEncoder
consoleEncoder := zapcore.NewConsoleEncoder(encoderConfig)
core := zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stdout), zapcore.DebugLevel)
logger = zap.New(core)
}
return logger, nil
}
11 changes: 11 additions & 0 deletions pkg/messages/host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package messages

// Host is the host details
type Host struct {
Namespace string
SourceService string
TargetService string
SourceHost string
TargetHost string
TrafficAllowed bool
}
File renamed without changes.
5 changes: 4 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package utils
import (
"crypto/sha256"
"encoding/hex"
"fmt"
)

func GetPrivateSerivceName(publicSVCName string) string {
hash := sha256.New()
hash.Write([]byte(publicSVCName))
hashed := hex.EncodeToString(hash.Sum(nil))
return publicSVCName + "-pvt" + "-" + string(hashed)[:10] + "-" + string(hashed)[11:16]
pvtName := publicSVCName + "-pvt" + "-" + string(hashed)[:10] + "-" + string(hashed)[11:16]
fmt.Println("Private name fetched is: ", pvtName)
return pvtName
}
8 changes: 0 additions & 8 deletions playground/.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# Used by the resolver
export POD_NAME=fake-api
export POD_IP=http://localhost:1090/mock/whatever-name-i-want/request
export MaxIdleProxyConns=100
export MaxIdleProxyConnsPerHost=1000

# Used by the target service
export TARGET_URL=http://localhost:1090/mock/whatever-name-i-want/request/

export KUBERNETES_SERVICE_HOST=10.96.0.1
export KUBERNETES_SERVICE_PORT=443


2 changes: 1 addition & 1 deletion playground/config/watch-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: elasti.truefoundry.io/v1alpha1
apiVersion: elasti.truefoundry.com/v1alpha1
kind: ElastiService
metadata:
labels:
Expand Down
6 changes: 6 additions & 0 deletions resolver/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Used by the resolver
export MaxIdleProxyConns=100
export MaxIdleProxyConnsPerHost=1000

export KUBERNETES_SERVICE_HOST=10.96.0.1
export KUBERNETES_SERVICE_PORT=443
19 changes: 19 additions & 0 deletions resolver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:1.22 AS builder

COPY ../pkg ../pkg
WORKDIR /workspace
COPY ./resolver/go.mod go.mod
COPY ./resolver/go.sum go.sum
RUN go mod download
COPY ./resolver/ .
RUN go build -o resolver ./cmd/
# Break
FROM alpine:latest
WORKDIR /
COPY --from=builder /workspace/resolver .
EXPOSE 8080
EXPOSE 8012
EXPOSE 8013
CMD ["./resolver"]


4 changes: 2 additions & 2 deletions resolver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ help:

.PHONY: run-resolver
run-resolver: ## Run resolver locally
go run ./cmd/resolver
go run ./cmd/

.PHONY: docker-build-resolver
docker-build-resolver: ## Build docker image for the resolver
docker build -t ${IMG} -f ./build/resolver/Dockerfile ../
docker build -t ${IMG} -f ./Dockerfile ../

.PHONY: docker-publish-resolver
docker-publish-resolver: ## Publish docker image for the resolver
Expand Down
18 changes: 0 additions & 18 deletions resolver/build/resolver/Dockerfile

This file was deleted.

Loading

0 comments on commit 28de9b0

Please sign in to comment.