diff --git a/.gitignore b/.gitignore index 5bb9de58..ec07599f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ # Binaries -fission-bundle/fission-bundle -fission/fission -environments/fetcher/cmd/fetcher -builder/cmd/builder -preupgradechecks/pre-upgrade-checks +cmd/fission-bundle/fission-bundle +cmd/fission-cli/fission +cmd/fetcher/fetcher +cmd/builder/builder +cmd/preupgradechecks/pre-upgrade-checks # Logs test/logs/ diff --git a/.travis.yml b/.travis.yml index 7035f1fc..adfa0d63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ services: before_install: - sudo apt-get update - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce - - sudo apt-get -y install apache2-utils parallel + - sudo apt-get -y install apache2-utils parallel realpath - sudo sysctl net.ipv6.conf.all.disable_ipv6=0 install: @@ -38,7 +38,7 @@ before_script: - helm lint charts/fission-all/ charts/fission-core/ - go mod download - go mod vendor - - go build -o fission/fission fission/*.go + - go build -o cmd/fission-cli/fission ./cmd/fission-cli/ - hack/runtests.sh script: diff --git a/Makefile b/Makefile index 1c406080..80ef0d06 100644 --- a/Makefile +++ b/Makefile @@ -20,21 +20,21 @@ ARCH ?= amd64 OS ?= linux test: - go test -v $(shell go list ./... | grep -v /examples/ | grep -v /environments/) + go test -v $(go list ./... | grep -v /examples/ | grep -v /environments/) build: build-bundle build-client build-client: - go build -o fission/fission ./fission/*.go + go build -o cmd/fission-cli/fission ./cmd/fission-cli/ build-bundle: - CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o fission-bundle/fission-bundle ./fission-bundle/*.go + CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o cmd/fission-bundle/fission-bundle ./cmd/fission-bundle/ build-image: - docker build --rm --tag "$(IMAGE):$(VERSION)" fission-bundle + docker build --rm --tag "$(IMAGE):$(VERSION)" cmd/fission-bundle/ install: - go install ./fission + go install ./cmd/fission-cli/ image: build-bundle build-image diff --git a/builder/cmd/Dockerfile.fission-builder b/cmd/builder/Dockerfile.fission-builder similarity index 68% rename from builder/cmd/Dockerfile.fission-builder rename to cmd/builder/Dockerfile.fission-builder index edd9f2b0..c87062e2 100644 --- a/builder/cmd/Dockerfile.fission-builder +++ b/cmd/builder/Dockerfile.fission-builder @@ -12,15 +12,15 @@ ARG BUILDDATE=unknown ARG GOPKG=github.com/fission/fission COPY . /go/src/${GOPKG} -WORKDIR /go/src/${GOPKG}/builder/cmd +WORKDIR /go/src/${GOPKG}/cmd/builder RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -o /go/bin/builder \ -gcflags=-trimpath=$GOPATH \ -asmflags=-trimpath=$GOPATH \ - -ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}" + -ldflags "-X github.com/fission/fission/pkg/info.GitCommit=${GITCOMMIT} -X github.com/fission/fission/pkg/info.BuildDate=${BUILDDATE} -X github.com/fission/fission/pkg/info.Version=${BUILDVERSION}" FROM alpine:3.5 COPY --from=fission-builder /go/bin/builder / EXPOSE 8001 -ENTRYPOINT ["/builder"] \ No newline at end of file +ENTRYPOINT ["/builder"] diff --git a/builder/cmd/main.go b/cmd/builder/app/server.go similarity index 61% rename from builder/cmd/main.go rename to cmd/builder/app/server.go index 5e3e852e..7f599855 100644 --- a/builder/cmd/main.go +++ b/cmd/builder/app/server.go @@ -14,41 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package app import ( - "log" "net/http" - "os" "go.uber.org/zap" - builder "github.com/fission/fission/builder" + builder "github.com/fission/fission/pkg/builder" ) // Usage: builder -func main() { - logger, err := zap.NewProduction() - if err != nil { - log.Fatalf("can't initialize zap logger: %v", err) - } - defer logger.Sync() - - dir := os.Args[1] - if _, err := os.Stat(dir); err != nil { - if os.IsNotExist(err) { - err = os.MkdirAll(dir, os.ModeDir|0700) - if err != nil { - logger.Fatal("error creating directory", zap.Error(err), zap.String("directory", dir)) - } - } - } - builder := builder.MakeBuilder(logger, dir) +func Run(logger *zap.Logger, shareVolume string) error { + builder := builder.MakeBuilder(logger, shareVolume) mux := http.NewServeMux() mux.HandleFunc("/", builder.Handler) mux.HandleFunc("/version", builder.VersionHandler) mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }) - http.ListenAndServe(":8001", mux) + return http.ListenAndServe(":8001", mux) } diff --git a/cmd/builder/main.go b/cmd/builder/main.go new file mode 100644 index 00000000..bc78c992 --- /dev/null +++ b/cmd/builder/main.go @@ -0,0 +1,48 @@ +/* +Copyright 2018 The Fission Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "log" + "os" + + "go.uber.org/zap" + + "github.com/fission/fission/cmd/builder/app" +) + +// Usage: builder +func main() { + logger, err := zap.NewProduction() + if err != nil { + log.Fatalf("can't initialize zap logger: %v", err) + } + defer logger.Sync() + + shareVolume := os.Args[1] + if _, err := os.Stat(shareVolume); err != nil { + if os.IsNotExist(err) { + err = os.MkdirAll(shareVolume, os.ModeDir|0700) + if err != nil { + logger.Fatal("error creating directory: %v", zap.Error(err), zap.String("directory", shareVolume)) + } + } + } + + err = app.Run(logger, shareVolume) + logger.Error("error running builder", zap.Error(err)) +} diff --git a/environments/fetcher/cmd/Dockerfile.fission-fetcher b/cmd/fetcher/Dockerfile.fission-fetcher similarity index 68% rename from environments/fetcher/cmd/Dockerfile.fission-fetcher rename to cmd/fetcher/Dockerfile.fission-fetcher index 8e149ae2..b736d4e0 100644 --- a/environments/fetcher/cmd/Dockerfile.fission-fetcher +++ b/cmd/fetcher/Dockerfile.fission-fetcher @@ -12,15 +12,15 @@ ARG BUILDDATE=unknown ARG GOPKG=github.com/fission/fission COPY . /go/src/${GOPKG} -WORKDIR /go/src/${GOPKG}/environments/fetcher/cmd +WORKDIR /go/src/${GOPKG}/cmd/fetcher RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ -o /go/bin/fetcher \ -gcflags=-trimpath=$GOPATH \ -asmflags=-trimpath=$GOPATH \ - -ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}" + -ldflags "-X github.com/fission/fission/pkg/info.GitCommit=${GITCOMMIT} -X github.com/fission/fission/pkg/info.BuildDate=${BUILDDATE} -X github.com/fission/fission/pkg/info.Version=${BUILDVERSION}" FROM alpine:3.4 COPY --from=builder /go/bin/fetcher / EXPOSE 8000 -ENTRYPOINT ["/fetcher"] \ No newline at end of file +ENTRYPOINT ["/fetcher"] diff --git a/environments/fetcher/cmd/main.go b/cmd/fetcher/app/server.go similarity index 90% rename from environments/fetcher/cmd/main.go rename to cmd/fetcher/app/server.go index c7e23985..24f669b2 100644 --- a/environments/fetcher/cmd/main.go +++ b/cmd/fetcher/app/server.go @@ -1,11 +1,10 @@ -package main +package app import ( "context" "encoding/json" "flag" "fmt" - "log" "net/http" "os" @@ -14,8 +13,8 @@ import ( "go.opencensus.io/trace" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/environments/fetcher" + "github.com/fission/fission/pkg/fetcher" + "github.com/fission/fission/pkg/types" ) func registerTraceExporter(collectorEndpoint string) error { @@ -41,14 +40,7 @@ func registerTraceExporter(collectorEndpoint string) error { return nil } -// Usage: fetcher -func main() { - logger, err := zap.NewProduction() - if err != nil { - log.Fatalf("can't initialize zap logger: %v", err) - } - defer logger.Sync() - +func Run(logger *zap.Logger) { flag.Usage = fetcherUsage collectorEndpoint := flag.String("jaeger-collector-endpoint", "", "") specializeOnStart := flag.Bool("specialize-on-startup", false, "Flag to activate specialize process at pod starup") @@ -86,7 +78,7 @@ func main() { // do specialization in other goroutine to prevent blocking in newdeploy go func() { if *specializeOnStart { - var specializeReq fission.FunctionSpecializeRequest + var specializeReq types.FunctionSpecializeRequest err := json.Unmarshal([]byte(*specializePayload), &specializeReq) if err != nil { diff --git a/cmd/fetcher/main.go b/cmd/fetcher/main.go new file mode 100644 index 00000000..45080d04 --- /dev/null +++ b/cmd/fetcher/main.go @@ -0,0 +1,36 @@ +/* +Copyright 2018 The Fission Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "log" + + "go.uber.org/zap" + + "github.com/fission/fission/cmd/fetcher/app" +) + +// Usage: fetcher +func main() { + logger, err := zap.NewProduction() + if err != nil { + log.Fatalf("can't initialize zap logger: %v", err) + } + defer logger.Sync() + + app.Run(logger) +} diff --git a/fission-bundle/Dockerfile.fission-bundle b/cmd/fission-bundle/Dockerfile.fission-bundle similarity index 71% rename from fission-bundle/Dockerfile.fission-bundle rename to cmd/fission-bundle/Dockerfile.fission-bundle index a950fff2..edae5b30 100644 --- a/fission-bundle/Dockerfile.fission-bundle +++ b/cmd/fission-bundle/Dockerfile.fission-bundle @@ -13,16 +13,16 @@ ARG BUILDDATE=unknown ARG GOPKG=github.com/fission/fission COPY . /go/src/${GOPKG} RUN rm -f /go/src/${GOPKG}/Dockerfile* -WORKDIR /go/src/${GOPKG}/fission-bundle +WORKDIR /go/src/${GOPKG}/cmd/fission-bundle ENV GO111MODULE=on RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -mod vendor \ -o /go/bin/fission-bundle \ -gcflags=-trimpath=$GOPATH \ -asmflags=-trimpath=$GOPATH \ - -ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}" + -ldflags "-X github.com/fission/fission/pkg/info.GitCommit=${GITCOMMIT} -X github.com/fission/fission/pkg/info.BuildDate=${BUILDDATE} -X github.com/fission/fission/pkg/info.Version=${BUILDVERSION}" FROM alpine:3.4 RUN apk add --update ca-certificates COPY --from=builder /go/bin/fission-bundle / -ENTRYPOINT ["/fission-bundle"] \ No newline at end of file +ENTRYPOINT ["/fission-bundle"] diff --git a/fission-bundle/main.go b/cmd/fission-bundle/main.go similarity index 94% rename from fission-bundle/main.go rename to cmd/fission-bundle/main.go index 1fb23af2..a4ab9238 100644 --- a/fission-bundle/main.go +++ b/cmd/fission-bundle/main.go @@ -12,16 +12,16 @@ import ( "go.opencensus.io/trace" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/buildermgr" - "github.com/fission/fission/controller" - "github.com/fission/fission/executor" - "github.com/fission/fission/kubewatcher" - functionLogger "github.com/fission/fission/logger" - "github.com/fission/fission/mqtrigger" - "github.com/fission/fission/router" - "github.com/fission/fission/storagesvc" - "github.com/fission/fission/timer" + "github.com/fission/fission/pkg/buildermgr" + "github.com/fission/fission/pkg/controller" + "github.com/fission/fission/pkg/executor" + "github.com/fission/fission/pkg/info" + "github.com/fission/fission/pkg/kubewatcher" + functionLogger "github.com/fission/fission/pkg/logger" + messagequeue "github.com/fission/fission/pkg/mqtrigger" + "github.com/fission/fission/pkg/router" + "github.com/fission/fission/pkg/storagesvc" + "github.com/fission/fission/pkg/timer" ) func runController(logger *zap.Logger, port int) { @@ -214,7 +214,7 @@ Options: } defer logger.Sync() - version := fmt.Sprintf("Fission Bundle Version: %v", fission.BuildInfo().String()) + version := fmt.Sprintf("Fission Bundle Version: %v", info.BuildInfo().String()) arguments, err := docopt.Parse(usage, nil, true, version, false) if err != nil { logger.Fatal("Could not parse command line arguments", zap.Error(err)) diff --git a/cmd/fission-cli/main.go b/cmd/fission-cli/main.go new file mode 100644 index 00000000..cc021f01 --- /dev/null +++ b/cmd/fission-cli/main.go @@ -0,0 +1,27 @@ +/* +Copyright 2018 The Fission Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "os" + + fcli "github.com/fission/fission/pkg/fission-cli" +) + +func main() { + fcli.NewCliApp().Run(os.Args) +} diff --git a/preupgradechecks/Dockerfile.fission-preupgradechecks b/cmd/preupgradechecks/Dockerfile.fission-preupgradechecks similarity index 71% rename from preupgradechecks/Dockerfile.fission-preupgradechecks rename to cmd/preupgradechecks/Dockerfile.fission-preupgradechecks index 797a076d..8c471404 100644 --- a/preupgradechecks/Dockerfile.fission-preupgradechecks +++ b/cmd/preupgradechecks/Dockerfile.fission-preupgradechecks @@ -12,12 +12,12 @@ ARG BUILDDATE=unknown ARG GOPKG=github.com/fission/fission COPY . /go/src/${GOPKG} -WORKDIR /go/src/${GOPKG}/preupgradechecks +WORKDIR /go/src/${GOPKG}/cmd/preupgradechecks RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \ -o /go/bin/pre-upgrade-checks \ -gcflags=-trimpath=$GOPATH \ -asmflags=-trimpath=$GOPATH \ - -ldflags "-X github.com/fission/fission.GitCommit=${GITCOMMIT} -X github.com/fission/fission.BuildDate=${BUILDDATE} -X github.com/fission/fission.Version=${BUILDVERSION}" + -ldflags "-X github.com/fission/fission/pkg/info.GitCommit=${GITCOMMIT} -X github.com/fission/fission/pkg/info.BuildDate=${BUILDDATE} -X github.com/fission/fission/pkg/info.Version=${BUILDVERSION}" FROM alpine:3.4 @@ -25,4 +25,4 @@ RUN apk add --update ca-certificates COPY --from=builder /go/bin/pre-upgrade-checks / ENTRYPOINT ["/pre-upgrade-checks"] -EXPOSE 8001 \ No newline at end of file +EXPOSE 8001 diff --git a/preupgradechecks/main.go b/cmd/preupgradechecks/main.go similarity index 94% rename from preupgradechecks/main.go rename to cmd/preupgradechecks/main.go index 39048777..5f9ebcfd 100644 --- a/preupgradechecks/main.go +++ b/cmd/preupgradechecks/main.go @@ -22,7 +22,7 @@ import ( "github.com/docopt/docopt-go" "go.uber.org/zap" - "github.com/fission/fission" + "github.com/fission/fission/pkg/info" ) func getStringArgWithDefault(arg interface{}, defaultValue string) string { @@ -47,7 +47,7 @@ Options: --fn-pod-namespace= Namespace where function pods get deployed. --envbuilder-namespace= Namespace where builder env pods are deployed.` - arguments, err := docopt.Parse(usage, nil, true, fission.BuildInfo().String(), false) + arguments, err := docopt.Parse(usage, nil, true, info.BuildInfo().String(), false) if err != nil { logger.Fatal("Could not parse command line arguments", zap.Error(err)) } diff --git a/preupgradechecks/preupgradechecks.go b/cmd/preupgradechecks/preupgradechecks.go similarity index 83% rename from preupgradechecks/preupgradechecks.go rename to cmd/preupgradechecks/preupgradechecks.go index 05bfb920..c14c3597 100644 --- a/preupgradechecks/preupgradechecks.go +++ b/cmd/preupgradechecks/preupgradechecks.go @@ -27,8 +27,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" ) type ( @@ -43,7 +45,7 @@ type ( ) const ( - MaxRetries = 5 + maxRetries = 5 FunctionCRD = "functions.fission.io" ) @@ -66,7 +68,7 @@ func makePreUpgradeTaskClient(logger *zap.Logger, fnPodNs, envBuilderNs string) // IsFissionReInstall checks if there is atleast one fission CRD, i.e. function in this case, on this cluster. // We need this to find out if fission had been previously installed on this cluster func (client *PreUpgradeTaskClient) IsFissionReInstall() bool { - for i := 0; i < MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { _, err := client.apiExtClient.ApiextensionsV1beta1().CustomResourceDefinitions().Get(FunctionCRD, metav1.GetOptions{}) if err != nil && k8serrors.IsNotFound(err) { return false @@ -86,9 +88,9 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences() { var result *multierror.Error var err error - var fList *crd.FunctionList + var fList *fv1.FunctionList - for i := 0; i < MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { fList, err = client.fissionClient.Functions(metav1.NamespaceAll).List(metav1.ListOptions{}) if err == nil { break @@ -98,7 +100,7 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences() { if err != nil { client.logger.Fatal("error listing functions after max retries", zap.Error(err), - zap.Int("max_retries", MaxRetries)) + zap.Int("max_retries", maxRetries)) } // check that all secrets, configmaps, packages are in the same namespace @@ -134,7 +136,7 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences() { // deleteClusterRoleBinding deletes the clusterRoleBinding passed as an argument to it. // If its not present, it just ignores and returns no errors func (client *PreUpgradeTaskClient) deleteClusterRoleBinding(clusterRoleBinding string) (err error) { - for i := 0; i < MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { err = client.k8sClient.RbacV1beta1().ClusterRoleBindings().Delete(clusterRoleBinding, &metav1.DeleteOptions{}) if err != nil && k8serrors.IsNotFound(err) || err == nil { return nil @@ -187,34 +189,34 @@ func (client *PreUpgradeTaskClient) SetupRoleBindings() { // the fact that we're here implies that there had been a prior installation of fission and objects are present still // so, we go ahead and create the role-bindings necessary for the fission-fetcher and fission-builder Service Accounts. - err := fission.SetupRoleBinding(client.logger, client.k8sClient, fission.PackageGetterRB, metav1.NamespaceDefault, fission.PackageGetterCR, fission.ClusterRole, fission.FissionFetcherSA, client.fnPodNs) + err := utils.SetupRoleBinding(client.logger, client.k8sClient, types.PackageGetterRB, metav1.NamespaceDefault, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, client.fnPodNs) if err != nil { client.logger.Fatal("error setting up rolebinding for service account", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), - zap.String("service_account", fission.FissionFetcherSA), + zap.String("role_binding", types.PackageGetterRB), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namespace", client.fnPodNs)) } - err = fission.SetupRoleBinding(client.logger, client.k8sClient, fission.PackageGetterRB, metav1.NamespaceDefault, fission.PackageGetterCR, fission.ClusterRole, fission.FissionBuilderSA, client.envBuilderNs) + err = utils.SetupRoleBinding(client.logger, client.k8sClient, types.PackageGetterRB, metav1.NamespaceDefault, types.PackageGetterCR, types.ClusterRole, types.FissionBuilderSA, client.envBuilderNs) if err != nil { client.logger.Fatal("error setting up rolebinding for service account", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), - zap.String("service_account", fission.FissionBuilderSA), + zap.String("role_binding", types.PackageGetterRB), + zap.String("service_account", types.FissionBuilderSA), zap.String("service_account_namespace", client.envBuilderNs)) } - err = fission.SetupRoleBinding(client.logger, client.k8sClient, fission.SecretConfigMapGetterRB, metav1.NamespaceDefault, fission.SecretConfigMapGetterCR, fission.ClusterRole, fission.FissionFetcherSA, client.fnPodNs) + err = utils.SetupRoleBinding(client.logger, client.k8sClient, types.SecretConfigMapGetterRB, metav1.NamespaceDefault, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, client.fnPodNs) if err != nil { client.logger.Fatal("error setting up rolebinding for service account", zap.Error(err), - zap.String("role_binding", fission.SecretConfigMapGetterRB), - zap.String("service_account", fission.FissionFetcherSA), + zap.String("role_binding", types.SecretConfigMapGetterRB), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namespace", client.fnPodNs)) } client.logger.Info("created rolebindings in default namespace", - zap.Strings("role_bindings", []string{fission.PackageGetterRB, fission.SecretConfigMapGetterRB})) + zap.Strings("role_bindings", []string{types.PackageGetterRB, types.SecretConfigMapGetterRB})) return } diff --git a/crd/types.go b/crd/types.go deleted file mode 100644 index c1c2803a..00000000 --- a/crd/types.go +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2016 The Fission Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package crd - -import ( - fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" -) - -type ( - Package = fv1.Package - PackageList = fv1.PackageList - Function = fv1.Function - FunctionList = fv1.FunctionList - Environment = fv1.Environment - EnvironmentList = fv1.EnvironmentList - HTTPTrigger = fv1.HTTPTrigger - HTTPTriggerList = fv1.HTTPTriggerList - KubernetesWatchTrigger = fv1.KubernetesWatchTrigger - KubernetesWatchTriggerList = fv1.KubernetesWatchTriggerList - TimeTrigger = fv1.TimeTrigger - TimeTriggerList = fv1.TimeTriggerList - MessageQueueTrigger = fv1.MessageQueueTrigger - MessageQueueTriggerList = fv1.MessageQueueTriggerList - Recorder = fv1.Recorder - RecorderList = fv1.RecorderList - CanaryConfig = fv1.CanaryConfig - CanaryConfigList = fv1.CanaryConfigList -) diff --git a/fission-bundle/push.sh b/fission-bundle/push.sh deleted file mode 100755 index 3442e6c3..00000000 --- a/fission-bundle/push.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e - -tag=$1 -if [ -z "$tag" ] -then - tag=latest -fi - -. build.sh - -docker build -t fission-bundle . -docker tag fission-bundle fission/fission-bundle:$tag -docker push fission/fission-bundle:$tag diff --git a/go.sum b/go.sum index 8737ed9f..418f62e8 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,7 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/blend/go-sdk v1.1.1 h1:R7PcwuIxYvrGc/r9TLLfMpajIboTjqs/HyQouzgJ7mQ= github.com/blend/go-sdk v1.1.1/go.mod h1:IP1XHXFveOXHRnojRJO7XvqWGqyzevtXND9AdSztAe8= github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A= github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM= @@ -33,6 +34,7 @@ github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9/go.mod h1:GgB8SF9nRG github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda h1:NyywMz59neOoVRFDz+ccfKWxn784fiHMDnZSy6T+JXY= github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= +github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536 h1:rHnpq7uNlix5l7tWZ55iJcHHrxCPnOVF4FGb7qOT2Jc= github.com/docopt/docopt-go v0.0.0-20160216232012-784ddc588536/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= @@ -47,6 +49,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1 github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -56,7 +59,9 @@ github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1 h1:72R+M5VuhED/KujmZVcIquuo8mBgX4oVda//DQb3PXo= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/golang/example v0.0.0-20170904185048-46695d81d1fa h1:iqCQC2Z53KkwGgTN9szyL4q0OQHmuNjeoNnMT6lk66k= github.com/golang/example v0.0.0-20170904185048-46695d81d1fa/go.mod h1:tO/5UvQ/uKigUjQBPqzstj6uxd3fUIjddi19DxGJeWg= +github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -106,6 +111,7 @@ github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 h1:/UewZcckqhvnnS github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -173,12 +179,15 @@ github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/ulikunitz/xz v0.0.0-20180703112113-636d36a76670 h1:HQWT4ta3wW5GZ790GaqLCS+w1dvuA3rMfEQxLi+UOYU= github.com/ulikunitz/xz v0.0.0-20180703112113-636d36a76670/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= +github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/wcharczuk/go-chart v2.0.1+incompatible h1:0pz39ZAycJFF7ju/1mepnk26RLVLBCWz1STcD3doU0A= github.com/wcharczuk/go-chart v2.0.1+incompatible/go.mod h1:PF5tmL4EIx/7Wf+hEkpCqYi5He4u90sw+0+6FhrryuE= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.18.0 h1:Mk5rgZcggtbvtAun5aJzAtjKKN/t0R3jJPlWILlv938= @@ -193,6 +202,7 @@ go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o= go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f h1:FO4MZ3N56GnxbqxGKqh+YTzUWQ2sDwtFQEZgLOxh9Jc= golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -230,6 +240,7 @@ google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+ google.golang.org/api v0.0.0-20190123234818-8001663557ac h1:cb/4gikrQnypAmwdJ80ZtUI2bY4iWg6PNxlMSW+iOoQ= google.golang.org/api v0.0.0-20190123234818-8001663557ac/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= diff --git a/hack/release-build.sh b/hack/release-build.sh index e3b0d1b5..da31e50a 100755 --- a/hack/release-build.sh +++ b/hack/release-build.sh @@ -3,7 +3,7 @@ set -e #set -x -DIR=$(realpath $(dirname $0))/../ +DIR=`realpath $(dirname $0)/../` BUILDDIR=$(realpath $DIR)/build # Build CLI binaries for mac/linux/windows @@ -26,7 +26,7 @@ build_cli() { local gitcommit=$5 arch="amd64" # parameterize if/when we need to - pushd $DIR/fission + pushd $DIR/cmd/fission-cli if [ "$osName" == "windows" ] then @@ -35,7 +35,8 @@ build_cli() { binary=fission-cli-${osName} fi - GOOS=$os GOARCH=$arch go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH -ldflags "-X github.com/fission/fission.GitCommit=$gitcommit -X github.com/fission/fission.BuildDate=$date -X github.com/fission/fission.Version=$version" -o $binary . + GOOS=$os GOARCH=$arch go build -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH \ + -ldflags "-X github.com/fission/fission/pkg/info.GitCommit=$gitcommit -X github.com/fission/fission/pkg/info.BuildDate=$date -X github.com/fission/fission/pkg/info.Version=$version" -o $binary . outdir=$BUILDDIR/cli/$osName/ mkdir -p $outdir @@ -52,8 +53,9 @@ build_fission_bundle_image() { local tag=fission/fission-bundle:$version - docker build -t $tag -f $ROOT/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version . - docker tag $tag fission/fission-bundle:latest + docker build -t $tag -f $DIR/cmd/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$gitcommit \ + --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version $DIR + docker tag $tag fission/fission-bundle:latest } build_fetcher_image() { @@ -62,12 +64,9 @@ build_fetcher_image() { local gitcommit=$3 local tag=fission/fetcher:$version - pushd $DIR/environments/fetcher/cmd - - docker build -t $tag -f $ROOT/environments/fetcher/cmd/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version . + docker build -t $tag -f $DIR/cmd/fetcher/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$gitcommit \ + --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version $DIR docker tag $tag fission/fetcher:latest - - popd } push_fetcher_image() { @@ -81,12 +80,9 @@ build_builder_image() { local gitcommit=$3 local tag=fission/builder:$version - pushd $DIR/builder/cmd - - docker build -t $tag -f $ROOT/builder/cmd/Dockerfile.fission-builder --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version . + docker build -t $tag -f $DIR/cmd/builder/Dockerfile.fission-builder --build-arg GITCOMMIT=$gitcommit \ + --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version $DIR docker tag $tag fission/builder:latest - - popd } build_env_image() { @@ -126,12 +122,9 @@ build_pre_upgrade_checks_image() { local tag=fission/pre-upgrade-checks:$version - pushd $DIR/preupgradechecks - - docker build -t $tag -f $ROOT/preupgradechecks/Dockerfile.fission-preupgradechecks --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version . + docker build -t $tag -f $DIR/cmd/preupgradechecks/Dockerfile.fission-preupgradechecks \ + --build-arg GITCOMMIT=$gitcommit --build-arg BUILDDATE=$date --build-arg BUILDVERSION=$version $DIR docker tag $tag fission/pre-upgrade-checks:latest - - popd } build_all_envs() { diff --git a/hack/release.sh b/hack/release.sh index 1e9d602f..f25c7f1f 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -325,6 +325,7 @@ fi release_environment_check $version $chartsrepo go mod vendor + # Build release-builder image docker build -t fission-release-builder -f $GOPATH/src/github.com/fission/fission/hack/Dockerfile . diff --git a/builder/builder.go b/pkg/builder/builder.go similarity index 98% rename from builder/builder.go rename to pkg/builder/builder.go index 8ac9c895..d1816152 100644 --- a/builder/builder.go +++ b/pkg/builder/builder.go @@ -34,7 +34,7 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission" + "github.com/fission/fission/pkg/info" ) const ( @@ -74,7 +74,7 @@ func MakeBuilder(logger *zap.Logger, sharedVolumePath string) *Builder { func (builder *Builder) VersionHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, fission.BuildInfo().String()) + fmt.Fprintf(w, info.BuildInfo().String()) } func (builder *Builder) Handler(w http.ResponseWriter, r *http.Request) { diff --git a/builder/client/client.go b/pkg/builder/client/client.go similarity index 91% rename from builder/client/client.go rename to pkg/builder/client/client.go index 4f1b7f76..a70e9aaa 100644 --- a/builder/client/client.go +++ b/pkg/builder/client/client.go @@ -27,8 +27,8 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission" - builder "github.com/fission/fission/builder" + builder "github.com/fission/fission/pkg/builder" + ferror "github.com/fission/fission/pkg/error" ) type ( @@ -61,7 +61,7 @@ func (c *Client) Build(req *builder.PackageBuildRequest) (*builder.PackageBuildR if resp.StatusCode == 200 { break } - err = fission.MakeErrorFromHTTP(resp) + err = ferror.MakeErrorFromHTTP(resp) } if i < maxRetries-1 { @@ -88,5 +88,5 @@ func (c *Client) Build(req *builder.PackageBuildRequest) (*builder.PackageBuildR return nil, err } - return &pkgBuildResp, fission.MakeErrorFromHTTP(resp) + return &pkgBuildResp, ferror.MakeErrorFromHTTP(resp) } diff --git a/buildermgr/buildermgr.go b/pkg/buildermgr/buildermgr.go similarity index 93% rename from buildermgr/buildermgr.go rename to pkg/buildermgr/buildermgr.go index 2c7b7900..f526a6ce 100644 --- a/buildermgr/buildermgr.go +++ b/pkg/buildermgr/buildermgr.go @@ -20,8 +20,8 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission/crd" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" + "github.com/fission/fission/pkg/crd" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" ) // Start the buildermgr service. diff --git a/buildermgr/common.go b/pkg/buildermgr/common.go similarity index 78% rename from buildermgr/common.go rename to pkg/buildermgr/common.go index 8b0a7178..8d16dcd9 100644 --- a/buildermgr/common.go +++ b/pkg/buildermgr/common.go @@ -26,11 +26,13 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/builder" - builderClient "github.com/fission/fission/builder/client" - "github.com/fission/fission/crd" - fetcherClient "github.com/fission/fission/environments/fetcher/client" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/builder" + builderClient "github.com/fission/fission/pkg/builder/client" + "github.com/fission/fission/pkg/crd" + ferror "github.com/fission/fission/pkg/error" + fetcherClient "github.com/fission/fission/pkg/fetcher/client" + "github.com/fission/fission/pkg/types" ) // buildPackage helps to build source package into deployment package. @@ -41,14 +43,14 @@ import ( // 4. Return upload response and build logs. // *. Return build logs and error if any one of steps above failed. func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, envBuilderNamespace string, - storageSvcUrl string, pkg *crd.Package) (uploadResp *fission.ArchiveUploadResponse, buildLogs string, err error) { + storageSvcUrl string, pkg *fv1.Package) (uploadResp *types.ArchiveUploadResponse, buildLogs string, err error) { env, err := fissionClient.Environments(pkg.Spec.Environment.Namespace).Get(pkg.Spec.Environment.Name) if err != nil { e := "error getting environment CRD info" logger.Error(e, zap.Error(err)) e = fmt.Sprintf("%s: %v", e, err) - return nil, e, fission.MakeError(http.StatusInternalServerError, e) + return nil, e, ferror.MakeError(http.StatusInternalServerError, e) } svcName := fmt.Sprintf("%v-%v.%v", env.Metadata.Name, env.Metadata.ResourceVersion, envBuilderNamespace) @@ -56,8 +58,8 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi fetcherC := fetcherClient.MakeClient(logger, fmt.Sprintf("http://%v:8000", svcName)) builderC := builderClient.MakeClient(logger, fmt.Sprintf("http://%v:8001", svcName)) - fetchReq := &fission.FunctionFetchRequest{ - FetchType: fission.FETCH_SOURCE, + fetchReq := &types.FunctionFetchRequest{ + FetchType: types.FETCH_SOURCE, Package: pkg.Metadata, Filename: srcPkgFilename, KeepArchive: false, @@ -69,7 +71,7 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi e := "error fetching source package" logger.Error(e, zap.Error(err)) e = fmt.Sprintf("%s: %v", e, err) - return nil, e, fission.MakeError(http.StatusInternalServerError, e) + return nil, e, ferror.MakeError(http.StatusInternalServerError, e) } buildCmd := pkg.Spec.BuildCommand @@ -92,14 +94,14 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi buildLogs = buildResp.BuildLogs } buildLogs += fmt.Sprintf("%v\n", e) - return nil, buildLogs, fission.MakeError(http.StatusInternalServerError, e) + return nil, buildLogs, ferror.MakeError(http.StatusInternalServerError, e) } logger.Info("build succeed", zap.String("source_package", srcPkgFilename), zap.String("deployment_package", buildResp.ArtifactFilename)) archivePackage := !env.Spec.KeepArchive - uploadReq := &fission.ArchiveUploadRequest{ + uploadReq := &types.ArchiveUploadRequest{ Filename: buildResp.ArtifactFilename, StorageSvcUrl: storageSvcUrl, ArchivePackage: archivePackage, @@ -111,24 +113,24 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi if err != nil { e := fmt.Sprintf("Error uploading deployment package: %v", err) buildResp.BuildLogs += fmt.Sprintf("%v\n", e) - return nil, buildResp.BuildLogs, fission.MakeError(http.StatusInternalServerError, e) + return nil, buildResp.BuildLogs, ferror.MakeError(http.StatusInternalServerError, e) } return uploadResp, buildResp.BuildLogs, nil } func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient, - pkg *crd.Package, status fission.BuildStatus, buildLogs string, - uploadResp *fission.ArchiveUploadResponse) (*crd.Package, error) { + pkg *fv1.Package, status fv1.BuildStatus, buildLogs string, + uploadResp *types.ArchiveUploadResponse) (*fv1.Package, error) { - pkg.Status = fission.PackageStatus{ + pkg.Status = fv1.PackageStatus{ BuildStatus: status, BuildLog: buildLogs, } if uploadResp != nil { - pkg.Spec.Deployment = fission.Archive{ - Type: fission.ArchiveTypeUrl, + pkg.Spec.Deployment = fv1.Archive{ + Type: types.ArchiveTypeUrl, URL: uploadResp.ArchiveDownloadUrl, Checksum: uploadResp.Checksum, } diff --git a/buildermgr/envwatcher.go b/pkg/buildermgr/envwatcher.go similarity index 94% rename from buildermgr/envwatcher.go rename to pkg/buildermgr/envwatcher.go index d237380d..0a12dff0 100644 --- a/buildermgr/envwatcher.go +++ b/pkg/buildermgr/envwatcher.go @@ -32,10 +32,12 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" - "github.com/fission/fission/executor/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/util" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" ) type requestType int @@ -65,8 +67,8 @@ type ( envwRequest struct { requestType - env *crd.Environment - envList []crd.Environment + env *fv1.Environment + envList []fv1.Environment respChan chan envwResponse } @@ -106,7 +108,7 @@ func makeEnvironmentWatcher( useIstio = istio } - builderImagePullPolicy := fission.GetImagePullPolicy(os.Getenv("BUILDER_IMAGE_PULL_POLICY")) + builderImagePullPolicy := utils.GetImagePullPolicy(os.Getenv("BUILDER_IMAGE_PULL_POLICY")) envWatcher := &environmentWatcher{ logger: logger.Named("environment_watcher"), @@ -151,7 +153,7 @@ func (envw *environmentWatcher) watchEnvironments() { ResourceVersion: rv, }) if err != nil { - if fission.IsNetworkError(err) { + if utils.IsNetworkError(err) { envw.logger.Error("encountered network error, retrying later", zap.Error(err)) time.Sleep(5 * time.Second) continue @@ -171,7 +173,7 @@ func (envw *environmentWatcher) watchEnvironments() { time.Sleep(time.Second) break } - env := ev.Object.(*crd.Environment) + env := ev.Object.(*fv1.Environment) rv = env.Metadata.ResourceVersion envw.sync() } @@ -183,7 +185,7 @@ func (envw *environmentWatcher) sync() { for i := 0; i < maxRetries; i++ { envList, err := envw.fissionClient.Environments(metav1.NamespaceAll).List(metav1.ListOptions{}) if err != nil { - if fission.IsNetworkError(err) { + if utils.IsNetworkError(err) { envw.logger.Error("error syncing environment CRD resources due to network error, retrying later", zap.Error(err)) time.Sleep(50 * time.Duration(2*i) * time.Millisecond) continue @@ -236,7 +238,7 @@ func (envw *environmentWatcher) service() { req.respChan <- envwResponse{builderInfo: builderInfo} case CLEANUP_BUILDERS: - latestEnvList := make(map[string]*crd.Environment) + latestEnvList := make(map[string]*fv1.Environment) for i := range req.envList { env := req.envList[i] // In order to support backward compatibility, for all builder images created in default @@ -298,7 +300,7 @@ func (envw *environmentWatcher) service() { } } -func (envw *environmentWatcher) getEnvBuilder(env *crd.Environment) (*builderInfo, error) { +func (envw *environmentWatcher) getEnvBuilder(env *fv1.Environment) (*builderInfo, error) { respChan := make(chan envwResponse) envw.requestChan <- envwRequest{ requestType: GET_BUILDER, @@ -309,14 +311,14 @@ func (envw *environmentWatcher) getEnvBuilder(env *crd.Environment) (*builderInf return resp.builderInfo, resp.err } -func (envw *environmentWatcher) cleanupEnvBuilders(envs []crd.Environment) { +func (envw *environmentWatcher) cleanupEnvBuilders(envs []fv1.Environment) { envw.requestChan <- envwRequest{ requestType: CLEANUP_BUILDERS, envList: envs, } } -func (envw *environmentWatcher) createBuilder(env *crd.Environment, ns string) (*builderInfo, error) { +func (envw *environmentWatcher) createBuilder(env *fv1.Environment, ns string) (*builderInfo, error) { var svc *apiv1.Service var deploy *v1beta1.Deployment @@ -345,9 +347,9 @@ func (envw *environmentWatcher) createBuilder(env *crd.Environment, ns string) ( // there should be only one deploy in deployList if len(deployList) == 0 { // create builder SA in this ns, if not already created - _, err := fission.SetupSA(envw.kubernetesClient, fission.FissionBuilderSA, ns) + _, err := utils.SetupSA(envw.kubernetesClient, types.FissionBuilderSA, ns) if err != nil { - return nil, errors.Wrapf(err, "error creating %q in ns: %s", fission.FissionBuilderSA, ns) + return nil, errors.Wrapf(err, "error creating %q in ns: %s", types.FissionBuilderSA, ns) } deploy, err = envw.createBuilderDeployment(env, ns) @@ -432,7 +434,7 @@ func (envw *environmentWatcher) getBuilderServiceList(sel map[string]string, ns return svcList.Items, nil } -func (envw *environmentWatcher) createBuilderService(env *crd.Environment, ns string) (*apiv1.Service, error) { +func (envw *environmentWatcher) createBuilderService(env *fv1.Environment, ns string) (*apiv1.Service, error) { name := fmt.Sprintf("%v-%v", env.Metadata.Name, env.Metadata.ResourceVersion) sel := envw.getLabels(env.Metadata.Name, ns, env.Metadata.ResourceVersion) service := apiv1.Service{ @@ -485,7 +487,7 @@ func (envw *environmentWatcher) getBuilderDeploymentList(sel map[string]string, return deployList.Items, nil } -func (envw *environmentWatcher) createBuilderDeployment(env *crd.Environment, ns string) (*v1beta1.Deployment, error) { +func (envw *environmentWatcher) createBuilderDeployment(env *fv1.Environment, ns string) (*v1beta1.Deployment, error) { name := fmt.Sprintf("%v-%v", env.Metadata.Name, env.Metadata.ResourceVersion) sel := envw.getLabels(env.Metadata.Name, ns, env.Metadata.ResourceVersion) var replicas int32 = 1 diff --git a/buildermgr/pkgwatcher.go b/pkg/buildermgr/pkgwatcher.go similarity index 86% rename from buildermgr/pkgwatcher.go rename to pkg/buildermgr/pkgwatcher.go index 2c4d869d..88dbf738 100644 --- a/buildermgr/pkgwatcher.go +++ b/pkg/buildermgr/pkgwatcher.go @@ -29,9 +29,11 @@ import ( "k8s.io/client-go/kubernetes" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" ) type ( @@ -73,10 +75,10 @@ func makePackageWatcher(logger *zap.Logger, fissionClient *crd.FissionClient, k8 // 5. Update package resource in package ref of functions that share the same package // 6. Update package status to succeed state // *. Update package status to failed state,if any one of steps above failed/time out -func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) { +func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package) { // Ignore non-pending state packages. - if srcpkg.Status.BuildStatus != fission.BuildStatusPending { + if srcpkg.Status.BuildStatus != fv1.BuildStatusPending { return } @@ -90,7 +92,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) pkgw.logger.Info("starting build for package", zap.String("package_name", srcpkg.Metadata.Name), zap.String("resource_version", srcpkg.Metadata.ResourceVersion)) - pkg, err := updatePackage(pkgw.logger, pkgw.fissionClient, srcpkg, fission.BuildStatusRunning, "", nil) + pkg, err := updatePackage(pkgw.logger, pkgw.fissionClient, srcpkg, fv1.BuildStatusRunning, "", nil) if err != nil { pkgw.logger.Error("error setting package pending state", zap.Error(err)) return @@ -101,7 +103,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) e := "environment does not exist" pkgw.logger.Error(e, zap.String("environment", pkg.Spec.Environment.Name)) updatePackage(pkgw.logger, pkgw.fissionClient, pkg, - fission.BuildStatusFailed, fmt.Sprintf("%s: %q", e, pkg.Spec.Environment.Name), nil) + fv1.BuildStatusFailed, fmt.Sprintf("%s: %q", e, pkg.Spec.Environment.Name), nil) return } @@ -155,17 +157,17 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) // Add the package getter rolebinding to builder sa // we continue here if role binding was not setup succeesffully. this is because without this, the fetcher wont be able to fetch the source pkg into the container and // the build will fail eventually - err := fission.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, fission.PackageGetterRB, pkg.Metadata.Namespace, fission.PackageGetterCR, fission.ClusterRole, fission.FissionBuilderSA, builderNs) + err := utils.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, types.PackageGetterRB, pkg.Metadata.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionBuilderSA, builderNs) if err != nil { pkgw.logger.Error("error setting up role binding for package", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), + zap.String("role_binding", types.PackageGetterRB), zap.String("package_name", pkg.Metadata.Name), zap.String("package_namespace", pkg.Metadata.Namespace)) continue } else { pkgw.logger.Info("setup rolebinding for sa package", - zap.String("sa", fmt.Sprintf("%s.%s", fission.FissionBuilderSA, builderNs)), + zap.String("sa", fmt.Sprintf("%s.%s", types.FissionBuilderSA, builderNs)), zap.String("package", fmt.Sprintf("%s.%s", pkg.Metadata.Name, pkg.Metadata.Namespace))) } @@ -173,7 +175,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) uploadResp, buildLogs, err := buildPackage(ctx, pkgw.logger, pkgw.fissionClient, builderNs, pkgw.storageSvcUrl, pkg) if err != nil { pkgw.logger.Error("error building package", zap.Error(err), zap.String("package_name", pkg.Metadata.Name)) - updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fission.BuildStatusFailed, buildLogs, nil) + updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil) return } @@ -185,7 +187,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) e := "error getting function list" pkgw.logger.Error(e, zap.Error(err)) buildLogs += fmt.Sprintf("%s: %v\n", e, err) - updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fission.BuildStatusFailed, buildLogs, nil) + updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil) } // A package may be used by multiple functions. Update @@ -201,17 +203,17 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) e := "error updating function package resource version" pkgw.logger.Error(e, zap.Error(err)) buildLogs += fmt.Sprintf("%s: %v\n", e, err) - updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fission.BuildStatusFailed, buildLogs, nil) + updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil) return } } } _, err = updatePackage(pkgw.logger, pkgw.fissionClient, pkg, - fission.BuildStatusSucceeded, buildLogs, uploadResp) + types.BuildStatusSucceeded, buildLogs, uploadResp) if err != nil { pkgw.logger.Error("error updating package info", zap.Error(err), zap.String("package_name", pkg.Metadata.Name)) - updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fission.BuildStatusFailed, buildLogs, nil) + updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil) return } @@ -221,7 +223,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *crd.Package) } // build timeout updatePackage(pkgw.logger, pkgw.fissionClient, pkg, - fission.BuildStatusFailed, "Build timeout due to environment builder not ready", nil) + types.BuildStatusFailed, "Build timeout due to environment builder not ready", nil) pkgw.logger.Error("max retries exceeded in building source package, timeout due to environment builder not ready", zap.String("package", fmt.Sprintf("%s.%s", pkg.Metadata.Name, pkg.Metadata.Namespace))) @@ -233,13 +235,13 @@ func (pkgw *packageWatcher) watchPackages(fissionClient *crd.FissionClient, kubernetesClient *kubernetes.Clientset, builderNamespace string) { buildCache := cache.MakeCache(0, 0) lw := k8sCache.NewListWatchFromClient(pkgw.fissionClient.GetCrdClient(), "packages", apiv1.NamespaceAll, fields.Everything()) - pkgStore, controller := k8sCache.NewInformer(lw, &crd.Package{}, 60*time.Second, k8sCache.ResourceEventHandlerFuncs{ + pkgStore, controller := k8sCache.NewInformer(lw, &fv1.Package{}, 60*time.Second, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - pkg := obj.(*crd.Package) + pkg := obj.(*fv1.Package) go pkgw.build(buildCache, pkg) }, UpdateFunc: func(oldObj, newObj interface{}) { - pkg := newObj.(*crd.Package) + pkg := newObj.(*fv1.Package) go pkgw.build(buildCache, pkg) }, }) diff --git a/cache/cache.go b/pkg/cache/cache.go similarity index 93% rename from cache/cache.go rename to pkg/cache/cache.go index d7c89c3e..387a6092 100644 --- a/cache/cache.go +++ b/pkg/cache/cache.go @@ -20,7 +20,7 @@ import ( "fmt" "time" - "github.com/fission/fission" + ferror "github.com/fission/fission/pkg/error" ) type requestType int @@ -94,10 +94,10 @@ func (c *Cache) service() { case GET: val, ok := c.cache[req.key] if !ok { - resp.error = fission.MakeError(fission.ErrorNotFound, + resp.error = ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("key '%v' not found", req.key)) } else if c.IsOld(val) { - resp.error = fission.MakeError(fission.ErrorNotFound, + resp.error = ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("key '%v' expired (atime %v)", req.key, val.atime)) delete(c.cache, req.key) } else { @@ -113,7 +113,7 @@ func (c *Cache) service() { val := c.cache[req.key] val.atime = time.Now() resp.existingValue = val.value - resp.error = fission.MakeError(fission.ErrorNameExists, "key already exists") + resp.error = ferror.MakeError(ferror.ErrorNameExists, "key already exists") } else { c.cache[req.key] = &Value{ value: req.value, @@ -139,7 +139,7 @@ func (c *Cache) service() { } req.responseChannel <- resp default: - resp.error = fission.MakeError(fission.ErrorInvalidArgument, + resp.error = ferror.MakeError(ferror.ErrorInvalidArgument, fmt.Sprintf("invalid request type: %v", req.requestType)) req.responseChannel <- resp } diff --git a/cache/cache_test.go b/pkg/cache/cache_test.go similarity index 100% rename from cache/cache_test.go rename to pkg/cache/cache_test.go diff --git a/canaryconfigmgr/canaryConfigCache.go b/pkg/canaryconfigmgr/canaryConfigCache.go similarity index 97% rename from canaryconfigmgr/canaryConfigCache.go rename to pkg/canaryconfigmgr/canaryConfigCache.go index 6d5c828f..4098e386 100644 --- a/canaryconfigmgr/canaryConfigCache.go +++ b/pkg/canaryconfigmgr/canaryConfigCache.go @@ -22,7 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/cache" + "github.com/fission/fission/pkg/cache" ) type ( diff --git a/canaryconfigmgr/canaryConfigMgr.go b/pkg/canaryconfigmgr/canaryConfigMgr.go similarity index 93% rename from canaryconfigmgr/canaryConfigMgr.go rename to pkg/canaryconfigmgr/canaryConfigMgr.go index 1c5fb386..c2911fa5 100644 --- a/canaryconfigmgr/canaryConfigMgr.go +++ b/pkg/canaryconfigmgr/canaryConfigMgr.go @@ -33,8 +33,13 @@ import ( "k8s.io/client-go/rest" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/types" +) + +const ( + maxRetries = 10 ) type canaryConfigMgr struct { @@ -99,23 +104,23 @@ func MakeCanaryConfigMgr(logger *zap.Logger, fissionClient *crd.FissionClient, k func (canaryCfgMgr *canaryConfigMgr) initCanaryConfigController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(canaryCfgMgr.crdClient, "canaryconfigs", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.CanaryConfig{}, resyncPeriod, + store, controller := k8sCache.NewInformer(listWatch, &fv1.CanaryConfig{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - canaryConfig := obj.(*crd.CanaryConfig) - if canaryConfig.Status.Status == fission.CanaryConfigStatusPending { + canaryConfig := obj.(*fv1.CanaryConfig) + if canaryConfig.Status.Status == types.CanaryConfigStatusPending { go canaryCfgMgr.addCanaryConfig(canaryConfig) } }, DeleteFunc: func(obj interface{}) { - canaryConfig := obj.(*crd.CanaryConfig) + canaryConfig := obj.(*fv1.CanaryConfig) go canaryCfgMgr.deleteCanaryConfig(canaryConfig) }, UpdateFunc: func(oldObj interface{}, newObj interface{}) { - oldConfig := oldObj.(*crd.CanaryConfig) - newConfig := newObj.(*crd.CanaryConfig) + oldConfig := oldObj.(*fv1.CanaryConfig) + newConfig := newObj.(*fv1.CanaryConfig) if oldConfig.Metadata.ResourceVersion != newConfig.Metadata.ResourceVersion && - newConfig.Status.Status == fission.CanaryConfigStatusPending { + newConfig.Status.Status == types.CanaryConfigStatusPending { canaryCfgMgr.logger.Info("update canary config invoked", zap.String("name", newConfig.Metadata.Name), zap.String("namespace", newConfig.Metadata.Namespace), @@ -135,7 +140,7 @@ func (canaryCfgMgr *canaryConfigMgr) Run(ctx context.Context) { canaryCfgMgr.logger.Info("started canary configmgr controller") } -func (canaryCfgMgr *canaryConfigMgr) addCanaryConfig(canaryConfig *crd.CanaryConfig) { +func (canaryCfgMgr *canaryConfigMgr) addCanaryConfig(canaryConfig *fv1.CanaryConfig) { canaryCfgMgr.logger.Info("addCanaryConfig called", zap.String("canary_config", canaryConfig.Metadata.Name)) // for each canary config, create a ticker with increment interval @@ -171,7 +176,7 @@ func (canaryCfgMgr *canaryConfigMgr) addCanaryConfig(canaryConfig *crd.CanaryCon canaryCfgMgr.processCanaryConfig(&ctx, canaryConfig, ticker) } -func (canaryCfgMgr *canaryConfigMgr) processCanaryConfig(ctx *context.Context, canaryConfig *crd.CanaryConfig, ticker *time.Ticker) { +func (canaryCfgMgr *canaryConfigMgr) processCanaryConfig(ctx *context.Context, canaryConfig *fv1.CanaryConfig, ticker *time.Ticker) { quit := make(chan struct{}) for { @@ -222,7 +227,7 @@ func (canaryCfgMgr *canaryConfigMgr) processCanaryConfig(ctx *context.Context, c } } -func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *crd.CanaryConfig, quit chan struct{}, ticker *time.Ticker) { +func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *fv1.CanaryConfig, quit chan struct{}, ticker *time.Ticker) { // handle race between delete event and notification on ticker.C _, err := canaryCfgMgr.canaryCfgCancelFuncMap.lookup(&canaryConfig.Metadata) if err != nil { @@ -258,7 +263,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *crd.CanaryC } // handle a race between ticker.Stop and receiving a notification on ticker.C - if canaryConfig.Status.Status != fission.CanaryConfigStatusPending { + if canaryConfig.Status.Status != types.CanaryConfigStatusPending { canaryCfgMgr.logger.Info("no need of processing the config, not pending anymore", zap.String("name", canaryConfig.Metadata.Name), zap.String("namespace", canaryConfig.Metadata.Namespace), @@ -266,7 +271,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *crd.CanaryC return } - if triggerObj.Spec.FunctionReference.Type == fission.FunctionReferenceTypeFunctionWeights && + if triggerObj.Spec.FunctionReference.Type == types.FunctionReferenceTypeFunctionWeights && triggerObj.Spec.FunctionReference.FunctionWeights[canaryConfig.Spec.NewFunction] != 0 { failurePercent, err := canaryCfgMgr.promClient.GetFunctionFailurePercentage(triggerObj.Spec.RelativeURL, triggerObj.Spec.Method, canaryConfig.Spec.NewFunction, canaryConfig.Metadata.Namespace, canaryConfig.Spec.WeightIncrementDuration) @@ -331,7 +336,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *crd.CanaryC // update the status of canary config as done processing, we dont care if we arent able to update because // resync takes care of the update err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.Metadata.Name, canaryConfig.Metadata.Namespace, - fission.CanaryConfigStatusSucceeded) + types.CanaryConfigStatusSucceeded) if err != nil { // cant do much after max retries other than logging it. canaryCfgMgr.logger.Error("error updating canary config after max retries", @@ -351,7 +356,7 @@ func (canaryCfgMgr *canaryConfigMgr) RollForwardOrBack(canaryConfig *crd.CanaryC } func (canaryCfgMgr *canaryConfigMgr) updateHttpTriggerWithRetries(triggerName, triggerNamespace string, fnWeights map[string]int) (err error) { - for i := 0; i < fission.MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { triggerObj, err := canaryCfgMgr.fissionClient.HTTPTriggers(triggerNamespace).Get(triggerName) if err != nil { e := "error getting http trigger object" @@ -386,7 +391,7 @@ func (canaryCfgMgr *canaryConfigMgr) updateHttpTriggerWithRetries(triggerName, t } func (canaryCfgMgr *canaryConfigMgr) updateCanaryConfigStatusWithRetries(cfgName, cfgNamespace string, status string) (err error) { - for i := 0; i < fission.MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { canaryCfgObj, err := canaryCfgMgr.fissionClient.CanaryConfigs(cfgNamespace).Get(cfgName) if err != nil { e := "error getting http canary config object" @@ -431,7 +436,7 @@ func (canaryCfgMgr *canaryConfigMgr) updateCanaryConfigStatusWithRetries(cfgName return err } -func (canaryCfgMgr *canaryConfigMgr) rollback(canaryConfig *crd.CanaryConfig, trigger *crd.HTTPTrigger) error { +func (canaryCfgMgr *canaryConfigMgr) rollback(canaryConfig *fv1.CanaryConfig, trigger *fv1.HTTPTrigger) error { functionWeights := trigger.Spec.FunctionReference.FunctionWeights functionWeights[canaryConfig.Spec.NewFunction] = 0 functionWeights[canaryConfig.Spec.OldFunction] = 100 @@ -439,12 +444,12 @@ func (canaryCfgMgr *canaryConfigMgr) rollback(canaryConfig *crd.CanaryConfig, tr err := canaryCfgMgr.updateHttpTriggerWithRetries(trigger.Metadata.Name, trigger.Metadata.Namespace, functionWeights) err = canaryCfgMgr.updateCanaryConfigStatusWithRetries(canaryConfig.Metadata.Name, canaryConfig.Metadata.Namespace, - fission.CanaryConfigStatusFailed) + types.CanaryConfigStatusFailed) return err } -func (canaryCfgMgr *canaryConfigMgr) rollForward(canaryConfig *crd.CanaryConfig, trigger *crd.HTTPTrigger) (bool, error) { +func (canaryCfgMgr *canaryConfigMgr) rollForward(canaryConfig *fv1.CanaryConfig, trigger *fv1.HTTPTrigger) (bool, error) { doneProcessingCanaryConfig := false functionWeights := trigger.Spec.FunctionReference.FunctionWeights @@ -469,9 +474,9 @@ func (canaryCfgMgr *canaryConfigMgr) rollForward(canaryConfig *crd.CanaryConfig, func (canaryCfgMgr *canaryConfigMgr) reSyncCanaryConfigs() { for _, obj := range canaryCfgMgr.canaryConfigStore.List() { - canaryConfig := obj.(*crd.CanaryConfig) + canaryConfig := obj.(*fv1.CanaryConfig) _, err := canaryCfgMgr.canaryCfgCancelFuncMap.lookup(&canaryConfig.Metadata) - if err != nil && canaryConfig.Status.Status == fission.CanaryConfigStatusPending { + if err != nil && canaryConfig.Status.Status == types.CanaryConfigStatusPending { canaryCfgMgr.logger.Info("adding canary config from resync loop", zap.String("name", canaryConfig.Metadata.Name), zap.String("namespace", canaryConfig.Metadata.Namespace), @@ -483,7 +488,7 @@ func (canaryCfgMgr *canaryConfigMgr) reSyncCanaryConfigs() { } } -func (canaryCfgMgr *canaryConfigMgr) deleteCanaryConfig(canaryConfig *crd.CanaryConfig) { +func (canaryCfgMgr *canaryConfigMgr) deleteCanaryConfig(canaryConfig *fv1.CanaryConfig) { canaryCfgMgr.logger.Info("delete event received for canary config", zap.String("name", canaryConfig.Metadata.Name), zap.String("namespace", canaryConfig.Metadata.Namespace), @@ -503,7 +508,7 @@ func (canaryCfgMgr *canaryConfigMgr) deleteCanaryConfig(canaryConfig *crd.Canary (*canaryProcessingInfo.CancelFunc)() } -func (canaryCfgMgr *canaryConfigMgr) updateCanaryConfig(oldCanaryConfig *crd.CanaryConfig, newCanaryConfig *crd.CanaryConfig) { +func (canaryCfgMgr *canaryConfigMgr) updateCanaryConfig(oldCanaryConfig *fv1.CanaryConfig, newCanaryConfig *fv1.CanaryConfig) { // before removing the object from cache, we need to get it's cancel func and cancel it canaryCfgMgr.deleteCanaryConfig(oldCanaryConfig) diff --git a/canaryconfigmgr/prometheusClient.go b/pkg/canaryconfigmgr/prometheusClient.go similarity index 100% rename from canaryconfigmgr/prometheusClient.go rename to pkg/canaryconfigmgr/prometheusClient.go diff --git a/controller/api.go b/pkg/controller/api.go similarity index 95% rename from controller/api.go rename to pkg/controller/api.go index 39925a37..6193b3ba 100644 --- a/controller/api.go +++ b/pkg/controller/api.go @@ -30,9 +30,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/logdb" + "github.com/fission/fission/pkg/crd" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/fission-cli/logdb" + "github.com/fission/fission/pkg/info" + "github.com/fission/fission/pkg/utils" ) var podNamespace string @@ -119,7 +121,7 @@ func (api *API) respondWithError(w http.ResponseWriter, err error) { return } - code, msg := fission.GetHTTPError(err) + code, msg := ferror.GetHTTPError(err) api.logger.Error(msg, zap.Int("code", code)) http.Error(w, msg, code) } @@ -168,11 +170,11 @@ func (api *API) getLogDBConfig(dbType string) logDBConfig { func (api *API) HomeHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, fission.ApiInfo().String()) + fmt.Fprintf(w, info.ApiInfo().String()) } func (api *API) ApiVersionMismatchHandler(w http.ResponseWriter, r *http.Request) { - err := fission.MakeError(fission.ErrorNotFound, "Fission server supports API v2 only -- v1 is not supported. Please upgrade your Fission client/CLI.") + err := ferror.MakeError(ferror.ErrorNotFound, "Fission server supports API v2 only -- v1 is not supported. Please upgrade your Fission client/CLI.") api.respondWithError(w, err) } @@ -272,7 +274,7 @@ func (api *API) Serve(port int) { address := fmt.Sprintf(":%v", port) api.logger.Info("server started", zap.Int("port", port)) - r.Use(fission.LoggingMiddleware(api.logger)) + r.Use(utils.LoggingMiddleware(api.logger)) err := http.ListenAndServe(address, r) api.logger.Fatal("done listening", zap.Error(err)) } diff --git a/controller/api_test.go b/pkg/controller/api_test.go similarity index 89% rename from controller/api_test.go rename to pkg/controller/api_test.go index d84511a0..13f35e91 100644 --- a/controller/api_test.go +++ b/pkg/controller/api_test.go @@ -32,9 +32,9 @@ import ( "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + ferror "github.com/fission/fission/pkg/error" ) var g struct { @@ -55,16 +55,16 @@ func assert(c bool, msg string) { func assertNameReuseFailure(err error, name string) { assert(err != nil, "recreating "+name+" with same name must fail") - fe, ok := err.(fission.Error) + fe, ok := err.(ferror.Error) assert(ok, "error must be a fission Error") - assert(fe.Code == fission.ErrorNameExists, "error must be a name exists error") + assert(fe.Code == ferror.ErrorNameExists, "error must be a name exists error") } func assertNotFoundFailure(err error, name string) { assert(err != nil, "requesting a non-existent "+name+" must fail") - fe, ok := err.(fission.Error) + fe, ok := err.(ferror.Error) assert(ok, "error must be a fission Error") - if fe.Code != fission.ErrorNotFound { + if fe.Code != ferror.ErrorNotFound { log.Fatalf("error must be a not found error: %v", fe) } } @@ -76,19 +76,19 @@ func assertCronSpecFails(err error) { } func TestFunctionApi(t *testing.T) { - testFunc := &crd.Function{ + testFunc := &fv1.Function{ Metadata: metav1.ObjectMeta{ Name: "foo", Namespace: metav1.NamespaceDefault, }, - Spec: fission.FunctionSpec{ - Environment: fission.EnvironmentReference{ + Spec: fv1.FunctionSpec{ + Environment: fv1.EnvironmentReference{ Name: "nodejs", Namespace: metav1.NamespaceDefault, }, - Package: fission.FunctionPackageRef{ + Package: fv1.FunctionPackageRef{ FunctionName: "xxx", - PackageRef: fission.PackageRef{ + PackageRef: fv1.PackageRef{ Namespace: metav1.NamespaceDefault, Name: "xxx", ResourceVersion: "12345", @@ -143,16 +143,16 @@ func TestFunctionApi(t *testing.T) { } func TestHTTPTriggerApi(t *testing.T) { - testTrigger := &crd.HTTPTrigger{ + testTrigger := &fv1.HTTPTrigger{ Metadata: metav1.ObjectMeta{ Name: "foo", Namespace: metav1.NamespaceDefault, }, - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ Method: http.MethodGet, RelativeURL: "/hello", - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: "foo", }, }, @@ -199,13 +199,13 @@ func TestHTTPTriggerApi(t *testing.T) { func TestEnvironmentApi(t *testing.T) { - testEnv := &crd.Environment{ + testEnv := &fv1.Environment{ Metadata: metav1.ObjectMeta{ Name: "foo", Namespace: metav1.NamespaceDefault, }, - Spec: fission.EnvironmentSpec{ - Runtime: fission.Runtime{ + Spec: fv1.EnvironmentSpec{ + Runtime: fv1.Runtime{ Image: "gcr.io/xyz", }, Resources: v1.ResourceRequirements{}, @@ -245,16 +245,16 @@ func TestEnvironmentApi(t *testing.T) { } func TestWatchApi(t *testing.T) { - testWatch := &crd.KubernetesWatchTrigger{ + testWatch := &fv1.KubernetesWatchTrigger{ Metadata: metav1.ObjectMeta{ Name: "xxx", Namespace: metav1.NamespaceDefault, }, - Spec: fission.KubernetesWatchTriggerSpec{ + Spec: fv1.KubernetesWatchTriggerSpec{ Namespace: "default", Type: "pod", - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: "foo", }, }, @@ -290,15 +290,15 @@ func TestWatchApi(t *testing.T) { } func TestTimeTriggerApi(t *testing.T) { - testTrigger := &crd.TimeTrigger{ + testTrigger := &fv1.TimeTrigger{ Metadata: metav1.ObjectMeta{ Name: "xxx", Namespace: metav1.NamespaceDefault, }, - Spec: fission.TimeTriggerSpec{ + Spec: fv1.TimeTriggerSpec{ Cron: "0 30 * * * *", - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: "asdf", }, }, diff --git a/controller/canaryConfigApi.go b/pkg/controller/canaryConfigApi.go similarity index 81% rename from controller/canaryConfigApi.go rename to pkg/controller/canaryConfigApi.go index c70db9d0..7aa44a67 100644 --- a/controller/canaryConfigApi.go +++ b/pkg/controller/canaryConfigApi.go @@ -26,15 +26,15 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - config "github.com/fission/fission/featureconfig" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" + config "github.com/fission/fission/pkg/featureconfig" ) func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) { featureErr := a.featureStatus[config.CanaryFeature] if len(featureErr) > 0 { - a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) + a.respondWithError(w, ferror.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) return } @@ -44,7 +44,7 @@ func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) { return } - var canaryCfg crd.CanaryConfig + var canaryCfg fv1.CanaryConfig err = json.Unmarshal(body, &canaryCfg) if err != nil { a.logger.Error("failed to unmarshal request body", zap.Error(err), zap.Binary("body", body)) @@ -71,7 +71,7 @@ func (a *API) CanaryConfigApiCreate(w http.ResponseWriter, r *http.Request) { func (a *API) CanaryConfigApiGet(w http.ResponseWriter, r *http.Request) { featureErr := a.featureStatus[config.CanaryFeature] if len(featureErr) > 0 { - a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) + a.respondWithError(w, ferror.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) return } @@ -101,7 +101,7 @@ func (a *API) CanaryConfigApiGet(w http.ResponseWriter, r *http.Request) { func (a *API) CanaryConfigApiList(w http.ResponseWriter, r *http.Request) { featureErr := a.featureStatus[config.CanaryFeature] if len(featureErr) > 0 { - a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) + a.respondWithError(w, ferror.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) return } @@ -128,7 +128,7 @@ func (a *API) CanaryConfigApiList(w http.ResponseWriter, r *http.Request) { func (a *API) CanaryConfigApiUpdate(w http.ResponseWriter, r *http.Request) { featureErr := a.featureStatus[config.CanaryFeature] if len(featureErr) > 0 { - a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) + a.respondWithError(w, ferror.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) return } @@ -138,7 +138,7 @@ func (a *API) CanaryConfigApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var c crd.CanaryConfig + var c fv1.CanaryConfig err = json.Unmarshal(body, &c) if err != nil { a.respondWithError(w, err) @@ -163,7 +163,7 @@ func (a *API) CanaryConfigApiUpdate(w http.ResponseWriter, r *http.Request) { func (a *API) CanaryConfigApiDelete(w http.ResponseWriter, r *http.Request) { featureErr := a.featureStatus[config.CanaryFeature] if len(featureErr) > 0 { - a.respondWithError(w, fission.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) + a.respondWithError(w, ferror.MakeError(http.StatusInternalServerError, fmt.Sprintf("Error enabling canary feature: %v", featureErr))) return } diff --git a/controller/client/canaryconfig.go b/pkg/controller/client/canaryconfig.go similarity index 87% rename from controller/client/canaryconfig.go rename to pkg/controller/client/canaryconfig.go index 31185d72..26a11459 100644 --- a/controller/client/canaryconfig.go +++ b/pkg/controller/client/canaryconfig.go @@ -24,10 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) CanaryConfigCreate(canaryConf *crd.CanaryConfig) (*metav1.ObjectMeta, error) { +func (c *Client) CanaryConfigCreate(canaryConf *fv1.CanaryConfig) (*metav1.ObjectMeta, error) { reqbody, err := json.Marshal(canaryConf) if err != nil { return nil, err @@ -53,7 +53,7 @@ func (c *Client) CanaryConfigCreate(canaryConf *crd.CanaryConfig) (*metav1.Objec return &m, nil } -func (c *Client) CanaryConfigGet(m *metav1.ObjectMeta) (*crd.CanaryConfig, error) { +func (c *Client) CanaryConfigGet(m *metav1.ObjectMeta) (*fv1.CanaryConfig, error) { relativeUrl := fmt.Sprintf("canaryconfigs/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -68,7 +68,7 @@ func (c *Client) CanaryConfigGet(m *metav1.ObjectMeta) (*crd.CanaryConfig, error return nil, err } - var canaryCfg crd.CanaryConfig + var canaryCfg fv1.CanaryConfig err = json.Unmarshal(body, &canaryCfg) if err != nil { return nil, err @@ -77,7 +77,7 @@ func (c *Client) CanaryConfigGet(m *metav1.ObjectMeta) (*crd.CanaryConfig, error return &canaryCfg, nil } -func (c *Client) CanaryConfigUpdate(canaryConf *crd.CanaryConfig) (*metav1.ObjectMeta, error) { +func (c *Client) CanaryConfigUpdate(canaryConf *fv1.CanaryConfig) (*metav1.ObjectMeta, error) { reqbody, err := json.Marshal(canaryConf) if err != nil { return nil, err @@ -110,7 +110,7 @@ func (c *Client) CanaryConfigDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) CanaryConfigList(ns string) ([]crd.CanaryConfig, error) { +func (c *Client) CanaryConfigList(ns string) ([]fv1.CanaryConfig, error) { relativeUrl := fmt.Sprintf("canaryconfigs?namespace=%v", ns) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -123,7 +123,7 @@ func (c *Client) CanaryConfigList(ns string) ([]crd.CanaryConfig, error) { return nil, err } - canaryCfgs := make([]crd.CanaryConfig, 0) + canaryCfgs := make([]fv1.CanaryConfig, 0) err = json.Unmarshal(body, &canaryCfgs) if err != nil { return nil, err diff --git a/controller/client/client.go b/pkg/controller/client/client.go similarity index 89% rename from controller/client/client.go rename to pkg/controller/client/client.go index f489eada..a1390853 100644 --- a/controller/client/client.go +++ b/pkg/controller/client/client.go @@ -25,7 +25,8 @@ import ( "net/http" "strings" - "github.com/fission/fission" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/info" ) type ( @@ -77,7 +78,7 @@ func (c *Client) url(relativeUrl string) string { func (c *Client) handleResponse(resp *http.Response) ([]byte, error) { if resp.StatusCode != 200 { - return nil, fission.MakeErrorFromHTTP(resp) + return nil, ferror.MakeErrorFromHTTP(resp) } body, err := ioutil.ReadAll(resp.Body) return body, err @@ -85,13 +86,13 @@ func (c *Client) handleResponse(resp *http.Response) ([]byte, error) { func (c *Client) handleCreateResponse(resp *http.Response) ([]byte, error) { if resp.StatusCode != 201 { - return nil, fission.MakeErrorFromHTTP(resp) + return nil, ferror.MakeErrorFromHTTP(resp) } body, err := ioutil.ReadAll(resp.Body) return body, err } -func (c *Client) ServerInfo() (*fission.ServerInfo, error) { +func (c *Client) ServerInfo() (*info.ServerInfo, error) { url := fmt.Sprintf(c.Url) resp, err := http.Get(url) if err != nil { @@ -104,7 +105,7 @@ func (c *Client) ServerInfo() (*fission.ServerInfo, error) { return nil, err } - info := &fission.ServerInfo{} + info := &info.ServerInfo{} err = json.Unmarshal(body, info) if err != nil { return nil, err diff --git a/controller/client/core.go b/pkg/controller/client/core.go similarity index 100% rename from controller/client/core.go rename to pkg/controller/client/core.go diff --git a/controller/client/environment.go b/pkg/controller/client/environment.go similarity index 89% rename from controller/client/environment.go rename to pkg/controller/client/environment.go index 08d02c13..83856205 100644 --- a/controller/client/environment.go +++ b/pkg/controller/client/environment.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) EnvironmentCreate(env *crd.Environment) (*metav1.ObjectMeta, error) { +func (c *Client) EnvironmentCreate(env *fv1.Environment) (*metav1.ObjectMeta, error) { err := env.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Environment", err) @@ -59,7 +58,7 @@ func (c *Client) EnvironmentCreate(env *crd.Environment) (*metav1.ObjectMeta, er return &m, nil } -func (c *Client) EnvironmentGet(m *metav1.ObjectMeta) (*crd.Environment, error) { +func (c *Client) EnvironmentGet(m *metav1.ObjectMeta) (*fv1.Environment, error) { relativeUrl := fmt.Sprintf("environments/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) EnvironmentGet(m *metav1.ObjectMeta) (*crd.Environment, error) return nil, err } - var env crd.Environment + var env fv1.Environment err = json.Unmarshal(body, &env) if err != nil { return nil, err @@ -83,7 +82,7 @@ func (c *Client) EnvironmentGet(m *metav1.ObjectMeta) (*crd.Environment, error) return &env, nil } -func (c *Client) EnvironmentUpdate(env *crd.Environment) (*metav1.ObjectMeta, error) { +func (c *Client) EnvironmentUpdate(env *fv1.Environment) (*metav1.ObjectMeta, error) { err := env.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Environment", err) @@ -121,7 +120,7 @@ func (c *Client) EnvironmentDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) EnvironmentList(ns string) ([]crd.Environment, error) { +func (c *Client) EnvironmentList(ns string) ([]fv1.Environment, error) { relativeUrl := fmt.Sprintf("environments?namespace=%v", ns) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -134,7 +133,7 @@ func (c *Client) EnvironmentList(ns string) ([]crd.Environment, error) { return nil, err } - envs := make([]crd.Environment, 0) + envs := make([]fv1.Environment, 0) err = json.Unmarshal(body, &envs) if err != nil { return nil, err diff --git a/controller/client/function.go b/pkg/controller/client/function.go similarity index 90% rename from controller/client/function.go rename to pkg/controller/client/function.go index e4e0898a..e69614cb 100644 --- a/controller/client/function.go +++ b/pkg/controller/client/function.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) FunctionCreate(f *crd.Function) (*metav1.ObjectMeta, error) { +func (c *Client) FunctionCreate(f *fv1.Function) (*metav1.ObjectMeta, error) { err := f.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Function", err) @@ -59,7 +58,7 @@ func (c *Client) FunctionCreate(f *crd.Function) (*metav1.ObjectMeta, error) { return &m, nil } -func (c *Client) FunctionGet(m *metav1.ObjectMeta) (*crd.Function, error) { +func (c *Client) FunctionGet(m *metav1.ObjectMeta) (*fv1.Function, error) { relativeUrl := fmt.Sprintf("functions/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) FunctionGet(m *metav1.ObjectMeta) (*crd.Function, error) { return nil, err } - var f crd.Function + var f fv1.Function err = json.Unmarshal(body, &f) if err != nil { return nil, err @@ -97,7 +96,7 @@ func (c *Client) FunctionGetRawDeployment(m *metav1.ObjectMeta) ([]byte, error) return c.handleResponse(resp) } -func (c *Client) FunctionUpdate(f *crd.Function) (*metav1.ObjectMeta, error) { +func (c *Client) FunctionUpdate(f *fv1.Function) (*metav1.ObjectMeta, error) { err := f.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Function", err) @@ -134,7 +133,7 @@ func (c *Client) FunctionDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) FunctionList(functionNamespace string) ([]crd.Function, error) { +func (c *Client) FunctionList(functionNamespace string) ([]fv1.Function, error) { relativeUrl := fmt.Sprintf("functions?namespace=%v", functionNamespace) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -147,7 +146,7 @@ func (c *Client) FunctionList(functionNamespace string) ([]crd.Function, error) return nil, err } - funcs := make([]crd.Function, 0) + funcs := make([]fv1.Function, 0) err = json.Unmarshal(body, &funcs) if err != nil { return nil, err diff --git a/controller/client/httptrigger.go b/pkg/controller/client/httptrigger.go similarity index 89% rename from controller/client/httptrigger.go rename to pkg/controller/client/httptrigger.go index 65f1448b..e0282942 100644 --- a/controller/client/httptrigger.go +++ b/pkg/controller/client/httptrigger.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) HTTPTriggerCreate(t *crd.HTTPTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) HTTPTriggerCreate(t *fv1.HTTPTrigger) (*metav1.ObjectMeta, error) { err := t.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("HTTPTrigger", err) @@ -59,7 +58,7 @@ func (c *Client) HTTPTriggerCreate(t *crd.HTTPTrigger) (*metav1.ObjectMeta, erro return &m, nil } -func (c *Client) HTTPTriggerGet(m *metav1.ObjectMeta) (*crd.HTTPTrigger, error) { +func (c *Client) HTTPTriggerGet(m *metav1.ObjectMeta) (*fv1.HTTPTrigger, error) { relativeUrl := fmt.Sprintf("triggers/http/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) HTTPTriggerGet(m *metav1.ObjectMeta) (*crd.HTTPTrigger, error) return nil, err } - var t crd.HTTPTrigger + var t fv1.HTTPTrigger err = json.Unmarshal(body, &t) if err != nil { return nil, err @@ -83,7 +82,7 @@ func (c *Client) HTTPTriggerGet(m *metav1.ObjectMeta) (*crd.HTTPTrigger, error) return &t, nil } -func (c *Client) HTTPTriggerUpdate(t *crd.HTTPTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) HTTPTriggerUpdate(t *fv1.HTTPTrigger) (*metav1.ObjectMeta, error) { err := t.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("HTTPTrigger", err) @@ -120,7 +119,7 @@ func (c *Client) HTTPTriggerDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) HTTPTriggerList(triggerNamespace string) ([]crd.HTTPTrigger, error) { +func (c *Client) HTTPTriggerList(triggerNamespace string) ([]fv1.HTTPTrigger, error) { relativeUrl := fmt.Sprintf("triggers/http?namespace=%v", triggerNamespace) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -133,7 +132,7 @@ func (c *Client) HTTPTriggerList(triggerNamespace string) ([]crd.HTTPTrigger, er return nil, err } - triggers := make([]crd.HTTPTrigger, 0) + triggers := make([]fv1.HTTPTrigger, 0) err = json.Unmarshal(body, &triggers) if err != nil { return nil, err diff --git a/controller/client/kuberneteswatchtrigger.go b/pkg/controller/client/kuberneteswatchtrigger.go similarity index 83% rename from controller/client/kuberneteswatchtrigger.go rename to pkg/controller/client/kuberneteswatchtrigger.go index 902eb93c..e2f2c38f 100644 --- a/controller/client/kuberneteswatchtrigger.go +++ b/pkg/controller/client/kuberneteswatchtrigger.go @@ -24,12 +24,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) -func (c *Client) WatchCreate(w *crd.KubernetesWatchTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) WatchCreate(w *fv1.KubernetesWatchTrigger) (*metav1.ObjectMeta, error) { err := w.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("KubernetesWatchTrigger", err) @@ -60,7 +59,7 @@ func (c *Client) WatchCreate(w *crd.KubernetesWatchTrigger) (*metav1.ObjectMeta, return &m, nil } -func (c *Client) WatchGet(m *metav1.ObjectMeta) (*crd.KubernetesWatchTrigger, error) { +func (c *Client) WatchGet(m *metav1.ObjectMeta) (*fv1.KubernetesWatchTrigger, error) { relativeUrl := fmt.Sprintf("watches/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -75,7 +74,7 @@ func (c *Client) WatchGet(m *metav1.ObjectMeta) (*crd.KubernetesWatchTrigger, er return nil, err } - var w crd.KubernetesWatchTrigger + var w fv1.KubernetesWatchTrigger err = json.Unmarshal(body, &w) if err != nil { return nil, err @@ -84,8 +83,8 @@ func (c *Client) WatchGet(m *metav1.ObjectMeta) (*crd.KubernetesWatchTrigger, er return &w, nil } -func (c *Client) WatchUpdate(w *crd.KubernetesWatchTrigger) (*metav1.ObjectMeta, error) { - return nil, fission.MakeError(fission.ErrorNotImplmented, +func (c *Client) WatchUpdate(w *fv1.KubernetesWatchTrigger) (*metav1.ObjectMeta, error) { + return nil, ferror.MakeError(ferror.ErrorNotImplmented, "watch update not implemented") } @@ -95,7 +94,7 @@ func (c *Client) WatchDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) WatchList(ns string) ([]crd.KubernetesWatchTrigger, error) { +func (c *Client) WatchList(ns string) ([]fv1.KubernetesWatchTrigger, error) { relativeUrl := fmt.Sprintf("watches?namespace=%v", ns) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -108,7 +107,7 @@ func (c *Client) WatchList(ns string) ([]crd.KubernetesWatchTrigger, error) { return nil, err } - watches := make([]crd.KubernetesWatchTrigger, 0) + watches := make([]fv1.KubernetesWatchTrigger, 0) err = json.Unmarshal(body, &watches) if err != nil { return nil, err diff --git a/controller/client/mqtrigger.go b/pkg/controller/client/mqtrigger.go similarity index 91% rename from controller/client/mqtrigger.go rename to pkg/controller/client/mqtrigger.go index 13aac948..adecfe93 100644 --- a/controller/client/mqtrigger.go +++ b/pkg/controller/client/mqtrigger.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) MessageQueueTriggerCreate(t *crd.MessageQueueTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) MessageQueueTriggerCreate(t *fv1.MessageQueueTrigger) (*metav1.ObjectMeta, error) { err := t.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("MessageQueueTrigger", err) @@ -59,7 +58,7 @@ func (c *Client) MessageQueueTriggerCreate(t *crd.MessageQueueTrigger) (*metav1. return &m, nil } -func (c *Client) MessageQueueTriggerGet(m *metav1.ObjectMeta) (*crd.MessageQueueTrigger, error) { +func (c *Client) MessageQueueTriggerGet(m *metav1.ObjectMeta) (*fv1.MessageQueueTrigger, error) { relativeUrl := fmt.Sprintf("triggers/messagequeue/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) MessageQueueTriggerGet(m *metav1.ObjectMeta) (*crd.MessageQueue return nil, err } - var t crd.MessageQueueTrigger + var t fv1.MessageQueueTrigger err = json.Unmarshal(body, &t) if err != nil { return nil, err @@ -83,7 +82,7 @@ func (c *Client) MessageQueueTriggerGet(m *metav1.ObjectMeta) (*crd.MessageQueue return &t, nil } -func (c *Client) MessageQueueTriggerUpdate(mqTrigger *crd.MessageQueueTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) MessageQueueTriggerUpdate(mqTrigger *fv1.MessageQueueTrigger) (*metav1.ObjectMeta, error) { err := mqTrigger.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("MessageQueueTrigger", err) @@ -120,7 +119,7 @@ func (c *Client) MessageQueueTriggerDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) MessageQueueTriggerList(mqType string, ns string) ([]crd.MessageQueueTrigger, error) { +func (c *Client) MessageQueueTriggerList(mqType string, ns string) ([]fv1.MessageQueueTrigger, error) { relativeUrl := "triggers/messagequeue" if len(mqType) > 0 { // TODO remove this, replace with field selector @@ -138,7 +137,7 @@ func (c *Client) MessageQueueTriggerList(mqType string, ns string) ([]crd.Messag return nil, err } - triggers := make([]crd.MessageQueueTrigger, 0) + triggers := make([]fv1.MessageQueueTrigger, 0) err = json.Unmarshal(body, &triggers) if err != nil { return nil, err diff --git a/controller/client/package.go b/pkg/controller/client/package.go similarity index 89% rename from controller/client/package.go rename to pkg/controller/client/package.go index 458e2f83..78922770 100644 --- a/controller/client/package.go +++ b/pkg/controller/client/package.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) PackageCreate(f *crd.Package) (*metav1.ObjectMeta, error) { +func (c *Client) PackageCreate(f *fv1.Package) (*metav1.ObjectMeta, error) { err := f.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Package", err) @@ -59,7 +58,7 @@ func (c *Client) PackageCreate(f *crd.Package) (*metav1.ObjectMeta, error) { return &m, nil } -func (c *Client) PackageGet(m *metav1.ObjectMeta) (*crd.Package, error) { +func (c *Client) PackageGet(m *metav1.ObjectMeta) (*fv1.Package, error) { relativeUrl := fmt.Sprintf("packages/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) PackageGet(m *metav1.ObjectMeta) (*crd.Package, error) { return nil, err } - var f crd.Package + var f fv1.Package err = json.Unmarshal(body, &f) if err != nil { return nil, err @@ -83,7 +82,7 @@ func (c *Client) PackageGet(m *metav1.ObjectMeta) (*crd.Package, error) { return &f, nil } -func (c *Client) PackageUpdate(f *crd.Package) (*metav1.ObjectMeta, error) { +func (c *Client) PackageUpdate(f *fv1.Package) (*metav1.ObjectMeta, error) { err := f.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Package", err) @@ -120,7 +119,7 @@ func (c *Client) PackageDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) PackageList(pkgNamespace string) ([]crd.Package, error) { +func (c *Client) PackageList(pkgNamespace string) ([]fv1.Package, error) { relativeUrl := fmt.Sprintf("packages?namespace=%v", pkgNamespace) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -133,7 +132,7 @@ func (c *Client) PackageList(pkgNamespace string) ([]crd.Package, error) { return nil, err } - funcs := make([]crd.Package, 0) + funcs := make([]fv1.Package, 0) err = json.Unmarshal(body, &funcs) if err != nil { return nil, err diff --git a/controller/client/recorder.go b/pkg/controller/client/recorder.go similarity index 92% rename from controller/client/recorder.go rename to pkg/controller/client/recorder.go index 4861a766..1d6f46e4 100644 --- a/controller/client/recorder.go +++ b/pkg/controller/client/recorder.go @@ -24,12 +24,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" - "github.com/fission/fission/redis/build/gen" + "github.com/fission/fission/pkg/redis/build/gen" ) -func (c *Client) RecorderCreate(r *crd.Recorder) (*metav1.ObjectMeta, error) { +func (c *Client) RecorderCreate(r *fv1.Recorder) (*metav1.ObjectMeta, error) { err := r.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Recorder", err) @@ -60,7 +59,7 @@ func (c *Client) RecorderCreate(r *crd.Recorder) (*metav1.ObjectMeta, error) { return &m, nil } -func (c *Client) RecorderGet(m *metav1.ObjectMeta) (*crd.Recorder, error) { +func (c *Client) RecorderGet(m *metav1.ObjectMeta) (*fv1.Recorder, error) { relativeUrl := fmt.Sprintf("recorders/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -75,7 +74,7 @@ func (c *Client) RecorderGet(m *metav1.ObjectMeta) (*crd.Recorder, error) { return nil, err } - var r crd.Recorder + var r fv1.Recorder err = json.Unmarshal(body, &r) if err != nil { return nil, err @@ -84,7 +83,7 @@ func (c *Client) RecorderGet(m *metav1.ObjectMeta) (*crd.Recorder, error) { return &r, nil } -func (c *Client) RecorderUpdate(recorder *crd.Recorder) (*metav1.ObjectMeta, error) { +func (c *Client) RecorderUpdate(recorder *fv1.Recorder) (*metav1.ObjectMeta, error) { err := recorder.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("Recorder", err) @@ -121,7 +120,7 @@ func (c *Client) RecorderDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) RecorderList(ns string) ([]crd.Recorder, error) { +func (c *Client) RecorderList(ns string) ([]fv1.Recorder, error) { relativeUrl := "recorders" resp, err := http.Get(c.url(relativeUrl)) @@ -135,7 +134,7 @@ func (c *Client) RecorderList(ns string) ([]crd.Recorder, error) { return nil, err } - recorders := make([]crd.Recorder, 0) + recorders := make([]fv1.Recorder, 0) err = json.Unmarshal(body, &recorders) if err != nil { return nil, err diff --git a/controller/client/replayer.go b/pkg/controller/client/replayer.go similarity index 100% rename from controller/client/replayer.go rename to pkg/controller/client/replayer.go diff --git a/controller/client/timetrigger.go b/pkg/controller/client/timetrigger.go similarity index 88% rename from controller/client/timetrigger.go rename to pkg/controller/client/timetrigger.go index ad8c9a79..4f5551ac 100644 --- a/controller/client/timetrigger.go +++ b/pkg/controller/client/timetrigger.go @@ -24,11 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -func (c *Client) TimeTriggerCreate(t *crd.TimeTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) TimeTriggerCreate(t *fv1.TimeTrigger) (*metav1.ObjectMeta, error) { err := t.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("TimeTrigger", err) @@ -59,7 +58,7 @@ func (c *Client) TimeTriggerCreate(t *crd.TimeTrigger) (*metav1.ObjectMeta, erro return &m, nil } -func (c *Client) TimeTriggerGet(m *metav1.ObjectMeta) (*crd.TimeTrigger, error) { +func (c *Client) TimeTriggerGet(m *metav1.ObjectMeta) (*fv1.TimeTrigger, error) { relativeUrl := fmt.Sprintf("triggers/time/%v", m.Name) relativeUrl += fmt.Sprintf("?namespace=%v", m.Namespace) @@ -74,7 +73,7 @@ func (c *Client) TimeTriggerGet(m *metav1.ObjectMeta) (*crd.TimeTrigger, error) return nil, err } - var t crd.TimeTrigger + var t fv1.TimeTrigger err = json.Unmarshal(body, &t) if err != nil { return nil, err @@ -83,7 +82,7 @@ func (c *Client) TimeTriggerGet(m *metav1.ObjectMeta) (*crd.TimeTrigger, error) return &t, nil } -func (c *Client) TimeTriggerUpdate(t *crd.TimeTrigger) (*metav1.ObjectMeta, error) { +func (c *Client) TimeTriggerUpdate(t *fv1.TimeTrigger) (*metav1.ObjectMeta, error) { err := t.Validate() if err != nil { return nil, fv1.AggregateValidationErrors("TimeTrigger", err) @@ -120,7 +119,7 @@ func (c *Client) TimeTriggerDelete(m *metav1.ObjectMeta) error { return c.delete(relativeUrl) } -func (c *Client) TimeTriggerList(ns string) ([]crd.TimeTrigger, error) { +func (c *Client) TimeTriggerList(ns string) ([]fv1.TimeTrigger, error) { relativeUrl := fmt.Sprintf("triggers/time?namespace=%v", ns) resp, err := http.Get(c.url(relativeUrl)) if err != nil { @@ -133,7 +132,7 @@ func (c *Client) TimeTriggerList(ns string) ([]crd.TimeTrigger, error) { return nil, err } - triggers := make([]crd.TimeTrigger, 0) + triggers := make([]fv1.TimeTrigger, 0) err = json.Unmarshal(body, &triggers) if err != nil { return nil, err diff --git a/controller/config.go b/pkg/controller/config.go similarity index 94% rename from controller/config.go rename to pkg/controller/config.go index 13c035dd..ee0106d1 100644 --- a/controller/config.go +++ b/pkg/controller/config.go @@ -23,9 +23,9 @@ import ( "go.uber.org/zap" "k8s.io/client-go/kubernetes" - "github.com/fission/fission/canaryconfigmgr" - "github.com/fission/fission/crd" - config "github.com/fission/fission/featureconfig" + "github.com/fission/fission/pkg/canaryconfigmgr" + "github.com/fission/fission/pkg/crd" + config "github.com/fission/fission/pkg/featureconfig" ) func ConfigCanaryFeature(context context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, kubeClient *kubernetes.Clientset, featureConfig *config.FeatureConfig, featureStatus map[string]string) error { diff --git a/controller/configmapApi.go b/pkg/controller/configmapApi.go similarity index 100% rename from controller/configmapApi.go rename to pkg/controller/configmapApi.go diff --git a/controller/controller.go b/pkg/controller/controller.go similarity index 93% rename from controller/controller.go rename to pkg/controller/controller.go index 5a4d2895..d5463e3b 100644 --- a/controller/controller.go +++ b/pkg/controller/controller.go @@ -21,14 +21,14 @@ import ( "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/utils" ) func Start(logger *zap.Logger, port int, unitTestFlag bool) { cLogger := logger.Named("controller") // setup a signal handler for SIGTERM - fission.SetupStackTraceHandler() + utils.SetupStackTraceHandler() fc, kc, apiExtClient, err := crd.MakeFissionClient() if err != nil { diff --git a/controller/crd.go b/pkg/controller/crd.go similarity index 96% rename from controller/crd.go rename to pkg/controller/crd.go index 61cf6202..8ccc289e 100644 --- a/controller/crd.go +++ b/pkg/controller/crd.go @@ -19,7 +19,7 @@ package controller import ( "go.uber.org/zap" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" ) func makeCRDBackedAPI(logger *zap.Logger) (*API, error) { diff --git a/controller/environmentApi.go b/pkg/controller/environmentApi.go similarity index 93% rename from controller/environmentApi.go rename to pkg/controller/environmentApi.go index 90000372..656cf867 100644 --- a/controller/environmentApi.go +++ b/pkg/controller/environmentApi.go @@ -25,8 +25,8 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) EnvironmentApiList(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func (a *API) EnvironmentApiCreate(w http.ResponseWriter, r *http.Request) { return } - var env crd.Environment + var env fv1.Environment err = json.Unmarshal(body, &env) if err != nil { a.logger.Error("failed to unmarshal request body", zap.Error(err), zap.Binary("body", body)) @@ -122,7 +122,7 @@ func (a *API) EnvironmentApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var env crd.Environment + var env fv1.Environment err = json.Unmarshal(body, &env) if err != nil { a.respondWithError(w, err) @@ -130,7 +130,7 @@ func (a *API) EnvironmentApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != env.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "Environment name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "Environment name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/functionApi.go b/pkg/controller/functionApi.go similarity index 96% rename from controller/functionApi.go rename to pkg/controller/functionApi.go index bdc00de2..b25a8e2e 100644 --- a/controller/functionApi.go +++ b/pkg/controller/functionApi.go @@ -32,8 +32,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" restclient "k8s.io/client-go/rest" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) getIstioServiceLabels(fnName string) map[string]string { @@ -70,7 +70,7 @@ func (a *API) FunctionApiCreate(w http.ResponseWriter, r *http.Request) { return } - var f crd.Function + var f fv1.Function err = json.Unmarshal(body, &f) if err != nil { a.respondWithError(w, err) @@ -132,7 +132,7 @@ func (a *API) FunctionApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var f crd.Function + var f fv1.Function err = json.Unmarshal(body, &f) if err != nil { a.respondWithError(w, err) @@ -140,7 +140,7 @@ func (a *API) FunctionApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != f.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "Function name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "Function name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/httpTriggerApi.go b/pkg/controller/httpTriggerApi.go similarity index 92% rename from controller/httpTriggerApi.go rename to pkg/controller/httpTriggerApi.go index 952a475d..f23856fd 100644 --- a/controller/httpTriggerApi.go +++ b/pkg/controller/httpTriggerApi.go @@ -25,8 +25,8 @@ import ( "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) HTTPTriggerApiList(w http.ResponseWriter, r *http.Request) { @@ -51,7 +51,7 @@ func (a *API) HTTPTriggerApiList(w http.ResponseWriter, r *http.Request) { } // checkHTTPTriggerDuplicates checks whether the tuple (Method, Host, URL) is duplicate or not. -func (a *API) checkHTTPTriggerDuplicates(t *crd.HTTPTrigger) error { +func (a *API) checkHTTPTriggerDuplicates(t *fv1.HTTPTrigger) error { triggers, err := a.fissionClient.HTTPTriggers(metav1.NamespaceAll).List(metav1.ListOptions{}) if err != nil { return err @@ -62,7 +62,7 @@ func (a *API) checkHTTPTriggerDuplicates(t *crd.HTTPTrigger) error { continue } if ht.Spec.RelativeURL == t.Spec.RelativeURL && ht.Spec.Method == t.Spec.Method && ht.Spec.Host == t.Spec.Host { - return fission.MakeError(fission.ErrorNameExists, + return ferror.MakeError(ferror.ErrorNameExists, fmt.Sprintf("HTTPTrigger with same Host, URL & method already exists (%v)", ht.Metadata.Name)) } @@ -77,7 +77,7 @@ func (a *API) HTTPTriggerApiCreate(w http.ResponseWriter, r *http.Request) { return } - var t crd.HTTPTrigger + var t fv1.HTTPTrigger err = json.Unmarshal(body, &t) if err != nil { a.respondWithError(w, err) @@ -147,7 +147,7 @@ func (a *API) HTTPTriggerApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var t crd.HTTPTrigger + var t fv1.HTTPTrigger err = json.Unmarshal(body, &t) if err != nil { a.respondWithError(w, err) @@ -155,7 +155,7 @@ func (a *API) HTTPTriggerApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != t.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "HTTPTrigger name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "HTTPTrigger name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/mqTriggerApi.go b/pkg/controller/mqTriggerApi.go similarity index 92% rename from controller/mqTriggerApi.go rename to pkg/controller/mqTriggerApi.go index 4b227a69..b5941d80 100644 --- a/controller/mqTriggerApi.go +++ b/pkg/controller/mqTriggerApi.go @@ -24,8 +24,8 @@ import ( "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) MessageQueueTriggerApiList(w http.ResponseWriter, r *http.Request) { @@ -55,7 +55,7 @@ func (a *API) MessageQueueTriggerApiCreate(w http.ResponseWriter, r *http.Reques return } - var mqTrigger crd.MessageQueueTrigger + var mqTrigger fv1.MessageQueueTrigger err = json.Unmarshal(body, &mqTrigger) if err != nil { a.respondWithError(w, err) @@ -115,7 +115,7 @@ func (a *API) MessageQueueTriggerApiUpdate(w http.ResponseWriter, r *http.Reques return } - var mqTrigger crd.MessageQueueTrigger + var mqTrigger fv1.MessageQueueTrigger err = json.Unmarshal(body, &mqTrigger) if err != nil { a.respondWithError(w, err) @@ -123,7 +123,7 @@ func (a *API) MessageQueueTriggerApiUpdate(w http.ResponseWriter, r *http.Reques } if name != mqTrigger.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "Message queue trigger name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "Message queue trigger name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/packageApi.go b/pkg/controller/packageApi.go similarity index 86% rename from controller/packageApi.go rename to pkg/controller/packageApi.go index 63d5737c..00420ff3 100644 --- a/controller/packageApi.go +++ b/pkg/controller/packageApi.go @@ -23,11 +23,12 @@ import ( "net/http" "github.com/dustin/go-humanize" + "github.com/fission/fission/pkg/types" "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) PackageApiList(w http.ResponseWriter, r *http.Request) { @@ -57,7 +58,7 @@ func (a *API) PackageApiCreate(w http.ResponseWriter, r *http.Request) { return } - var f crd.Package + var f fv1.Package err = json.Unmarshal(body, &f) if err != nil { a.respondWithError(w, err) @@ -65,15 +66,15 @@ func (a *API) PackageApiCreate(w http.ResponseWriter, r *http.Request) { } // Ensure size limits - if len(f.Spec.Source.Literal) > int(fission.ArchiveLiteralSizeLimit) { - err := fission.MakeError(fission.ErrorInvalidArgument, - fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(fission.ArchiveLiteralSizeLimit)))) + if len(f.Spec.Source.Literal) > int(types.ArchiveLiteralSizeLimit) { + err := ferror.MakeError(ferror.ErrorInvalidArgument, + fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(types.ArchiveLiteralSizeLimit)))) a.respondWithError(w, err) return } - if len(f.Spec.Deployment.Literal) > int(fission.ArchiveLiteralSizeLimit) { - err := fission.MakeError(fission.ErrorInvalidArgument, - fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(fission.ArchiveLiteralSizeLimit)))) + if len(f.Spec.Deployment.Literal) > int(types.ArchiveLiteralSizeLimit) { + err := ferror.MakeError(ferror.ErrorInvalidArgument, + fmt.Sprintf("Package literal larger than %s", humanize.Bytes(uint64(types.ArchiveLiteralSizeLimit)))) a.respondWithError(w, err) return } @@ -139,7 +140,7 @@ func (a *API) PackageApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var f crd.Package + var f fv1.Package err = json.Unmarshal(body, &f) if err != nil { a.respondWithError(w, err) @@ -147,7 +148,7 @@ func (a *API) PackageApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != f.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "Package name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "Package name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/recorderApi.go b/pkg/controller/recorderApi.go similarity index 92% rename from controller/recorderApi.go rename to pkg/controller/recorderApi.go index 357c821b..8203574c 100644 --- a/controller/recorderApi.go +++ b/pkg/controller/recorderApi.go @@ -24,8 +24,8 @@ import ( "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) RecorderApiList(w http.ResponseWriter, r *http.Request) { @@ -50,7 +50,7 @@ func (a *API) RecorderApiCreate(w http.ResponseWriter, r *http.Request) { return } - var recorder crd.Recorder + var recorder fv1.Recorder err = json.Unmarshal(body, &recorder) if err != nil { a.respondWithError(w, err) @@ -103,7 +103,7 @@ func (a *API) RecorderApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var recorder crd.Recorder + var recorder fv1.Recorder err = json.Unmarshal(body, &recorder) if err != nil { a.respondWithError(w, err) @@ -111,7 +111,7 @@ func (a *API) RecorderApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != recorder.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "Recorder name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "Recorder name doesn't match URL") a.respondWithError(w, err) return } diff --git a/controller/recordsApi.go b/pkg/controller/recordsApi.go similarity index 98% rename from controller/recordsApi.go rename to pkg/controller/recordsApi.go index e801e486..db7b511e 100644 --- a/controller/recordsApi.go +++ b/pkg/controller/recordsApi.go @@ -22,7 +22,7 @@ import ( "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/redis" + "github.com/fission/fission/pkg/redis" ) func (a *API) RecordsApiListAll(w http.ResponseWriter, r *http.Request) { diff --git a/controller/replayAPI.go b/pkg/controller/replayAPI.go similarity index 96% rename from controller/replayAPI.go rename to pkg/controller/replayAPI.go index c1a7cc21..190600a2 100644 --- a/controller/replayAPI.go +++ b/pkg/controller/replayAPI.go @@ -22,7 +22,7 @@ import ( "github.com/gorilla/mux" - "github.com/fission/fission/redis" + "github.com/fission/fission/pkg/redis" ) func (a *API) ReplayByReqUID(w http.ResponseWriter, r *http.Request) { diff --git a/controller/secretApi.go b/pkg/controller/secretApi.go similarity index 100% rename from controller/secretApi.go rename to pkg/controller/secretApi.go diff --git a/controller/storagesvc.go b/pkg/controller/storagesvc.go similarity index 100% rename from controller/storagesvc.go rename to pkg/controller/storagesvc.go diff --git a/controller/timeTriggerApi.go b/pkg/controller/timeTriggerApi.go similarity index 89% rename from controller/timeTriggerApi.go rename to pkg/controller/timeTriggerApi.go index 0ef5bf50..b7e157b8 100644 --- a/controller/timeTriggerApi.go +++ b/pkg/controller/timeTriggerApi.go @@ -25,8 +25,8 @@ import ( "github.com/robfig/cron" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) TimeTriggerApiList(w http.ResponseWriter, r *http.Request) { @@ -57,7 +57,7 @@ func (a *API) TimeTriggerApiCreate(w http.ResponseWriter, r *http.Request) { return } - var t crd.TimeTrigger + var t fv1.TimeTrigger err = json.Unmarshal(body, &t) if err != nil { a.respondWithError(w, err) @@ -67,7 +67,7 @@ func (a *API) TimeTriggerApiCreate(w http.ResponseWriter, r *http.Request) { // validate _, err = cron.Parse(t.Spec.Cron) if err != nil { - err = fission.MakeError(fission.ErrorInvalidArgument, "TimeTrigger cron spec is not valid") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "TimeTrigger cron spec is not valid") a.respondWithError(w, err) return } @@ -128,7 +128,7 @@ func (a *API) TimeTriggerApiUpdate(w http.ResponseWriter, r *http.Request) { return } - var t crd.TimeTrigger + var t fv1.TimeTrigger err = json.Unmarshal(body, &t) if err != nil { a.respondWithError(w, err) @@ -136,14 +136,14 @@ func (a *API) TimeTriggerApiUpdate(w http.ResponseWriter, r *http.Request) { } if name != t.Metadata.Name { - err = fission.MakeError(fission.ErrorInvalidArgument, "TimeTrigger name doesn't match URL") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "TimeTrigger name doesn't match URL") a.respondWithError(w, err) return } _, err = cron.Parse(t.Spec.Cron) if err != nil { - err = fission.MakeError(fission.ErrorInvalidArgument, "TimeTrigger cron spec is not valid") + err = ferror.MakeError(ferror.ErrorInvalidArgument, "TimeTrigger cron spec is not valid") a.respondWithError(w, err) return } diff --git a/controller/watchApi.go b/pkg/controller/watchApi.go similarity index 93% rename from controller/watchApi.go rename to pkg/controller/watchApi.go index fd92647e..205d5475 100644 --- a/controller/watchApi.go +++ b/pkg/controller/watchApi.go @@ -24,8 +24,8 @@ import ( "github.com/gorilla/mux" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" ) func (a *API) WatchApiList(w http.ResponseWriter, r *http.Request) { @@ -56,7 +56,7 @@ func (a *API) WatchApiCreate(w http.ResponseWriter, r *http.Request) { return } - var watch crd.KubernetesWatchTrigger + var watch fv1.KubernetesWatchTrigger err = json.Unmarshal(body, &watch) if err != nil { a.respondWithError(w, err) @@ -112,7 +112,7 @@ func (a *API) WatchApiGet(w http.ResponseWriter, r *http.Request) { } func (a *API) WatchApiUpdate(w http.ResponseWriter, r *http.Request) { - a.respondWithError(w, fission.MakeError(fission.ErrorNotImplmented, + a.respondWithError(w, ferror.MakeError(ferror.ErrorNotImplmented, "Not implemented")) } diff --git a/controller/workflowApiProxy.go b/pkg/controller/workflowApiProxy.go similarity index 100% rename from controller/workflowApiProxy.go rename to pkg/controller/workflowApiProxy.go diff --git a/crd/canaryConfig.go b/pkg/crd/canaryConfig.go similarity index 76% rename from crd/canaryConfig.go rename to pkg/crd/canaryConfig.go index 69a00368..860ec5ae 100644 --- a/crd/canaryConfig.go +++ b/pkg/crd/canaryConfig.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( CanaryConfigInterface interface { - Create(*CanaryConfig) (*CanaryConfig, error) - Get(name string) (*CanaryConfig, error) - Update(*CanaryConfig) (*CanaryConfig, error) + Create(*fv1.CanaryConfig) (*fv1.CanaryConfig, error) + Get(name string) (*fv1.CanaryConfig, error) + Update(*fv1.CanaryConfig) (*fv1.CanaryConfig, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*CanaryConfigList, error) + List(opts metav1.ListOptions) (*fv1.CanaryConfigList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeCanaryConfigInterface(crdClient *rest.RESTClient, namespace string) Can } } -func (c *canaryConfigClient) Create(f *CanaryConfig) (*CanaryConfig, error) { - var result CanaryConfig +func (c *canaryConfigClient) Create(f *fv1.CanaryConfig) (*fv1.CanaryConfig, error) { + var result fv1.CanaryConfig err := c.client.Post(). Resource("canaryconfigs"). Namespace(c.namespace). @@ -59,8 +61,8 @@ func (c *canaryConfigClient) Create(f *CanaryConfig) (*CanaryConfig, error) { return &result, nil } -func (c *canaryConfigClient) Get(name string) (*CanaryConfig, error) { - var result CanaryConfig +func (c *canaryConfigClient) Get(name string) (*fv1.CanaryConfig, error) { + var result fv1.CanaryConfig err := c.client.Get(). Resource("canaryconfigs"). Namespace(c.namespace). @@ -72,8 +74,8 @@ func (c *canaryConfigClient) Get(name string) (*CanaryConfig, error) { return &result, nil } -func (c *canaryConfigClient) Update(f *CanaryConfig) (*CanaryConfig, error) { - var result CanaryConfig +func (c *canaryConfigClient) Update(f *fv1.CanaryConfig) (*fv1.CanaryConfig, error) { + var result fv1.CanaryConfig err := c.client.Put(). Resource("canaryconfigs"). Namespace(c.namespace). @@ -96,8 +98,8 @@ func (c *canaryConfigClient) Delete(name string, opts *metav1.DeleteOptions) err Error() } -func (c *canaryConfigClient) List(opts metav1.ListOptions) (*CanaryConfigList, error) { - var result CanaryConfigList +func (c *canaryConfigClient) List(opts metav1.ListOptions) (*fv1.CanaryConfigList, error) { + var result fv1.CanaryConfigList err := c.client.Get(). Namespace(c.namespace). Resource("canaryconfigs"). diff --git a/crd/client.go b/pkg/crd/client.go similarity index 91% rename from crd/client.go rename to pkg/crd/client.go index 1ae115ac..fc379954 100644 --- a/crd/client.go +++ b/pkg/crd/client.go @@ -31,6 +31,8 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( @@ -106,64 +108,64 @@ func configureClient(config *rest.Config) { func(scheme *runtime.Scheme) error { scheme.AddKnownTypes( groupversion, - &Function{}, - &FunctionList{}, + &fv1.Function{}, + &fv1.FunctionList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &Environment{}, - &EnvironmentList{}, + &fv1.Environment{}, + &fv1.EnvironmentList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &HTTPTrigger{}, - &HTTPTriggerList{}, + &fv1.HTTPTrigger{}, + &fv1.HTTPTriggerList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &KubernetesWatchTrigger{}, - &KubernetesWatchTriggerList{}, + &fv1.KubernetesWatchTrigger{}, + &fv1.KubernetesWatchTriggerList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &TimeTrigger{}, - &TimeTriggerList{}, + &fv1.TimeTrigger{}, + &fv1.TimeTriggerList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &MessageQueueTrigger{}, - &MessageQueueTriggerList{}, + &fv1.MessageQueueTrigger{}, + &fv1.MessageQueueTriggerList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &Package{}, - &PackageList{}, + &fv1.Package{}, + &fv1.PackageList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &Recorder{}, - &RecorderList{}, + &fv1.Recorder{}, + &fv1.RecorderList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) scheme.AddKnownTypes( groupversion, - &CanaryConfig{}, - &CanaryConfigList{}, + &fv1.CanaryConfig{}, + &fv1.CanaryConfigList{}, &metav1.ListOptions{}, &metav1.DeleteOptions{}, ) diff --git a/crd/crd.go b/pkg/crd/crd.go similarity index 100% rename from crd/crd.go rename to pkg/crd/crd.go diff --git a/crd/crd_test.go b/pkg/crd/crd_test.go similarity index 91% rename from crd/crd_test.go rename to pkg/crd/crd_test.go index 01e86300..24b4882d 100644 --- a/crd/crd_test.go +++ b/pkg/crd/crd_test.go @@ -26,7 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/rest" - "github.com/fission/fission" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) func panicIf(err error) { @@ -37,24 +37,24 @@ func panicIf(err error) { func functionTests(crdClient *rest.RESTClient) { // sample function object - function := &Function{ + function := &fv1.Function{ TypeMeta: metav1.TypeMeta{ Kind: "Function", - APIVersion: "fission.io/v1", + APIVersion: "fv1.io/v1", }, Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: metav1.NamespaceDefault, }, - Spec: fission.FunctionSpec{ - Package: fission.FunctionPackageRef{ - PackageRef: fission.PackageRef{ + Spec: fv1.FunctionSpec{ + Package: fv1.FunctionPackageRef{ + PackageRef: fv1.PackageRef{ Name: "foo", Namespace: "bar", }, FunctionName: "hello", }, - Environment: fission.EnvironmentReference{ + Environment: fv1.EnvironmentReference{ Name: "xxx", }, }, @@ -122,7 +122,7 @@ func functionTests(crdClient *rest.RESTClient) { log.Panicf("Didn't get watch event") } case ev := <-wi.ResultChan(): - wf, ok := ev.Object.(*Function) + wf, ok := ev.Object.(*fv1.Function) if !ok { log.Panicf("Can't cast to Function") } @@ -137,20 +137,20 @@ func functionTests(crdClient *rest.RESTClient) { func environmentTests(crdClient *rest.RESTClient) { // sample environment object - environment := &Environment{ + environment := &fv1.Environment{ TypeMeta: metav1.TypeMeta{ Kind: "Environment", - APIVersion: "fission.io/v1", + APIVersion: "fv1.io/v1", }, Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: metav1.NamespaceDefault, }, - Spec: fission.EnvironmentSpec{ - Runtime: fission.Runtime{ + Spec: fv1.EnvironmentSpec{ + Runtime: fv1.Runtime{ Image: "xxx", }, - Builder: fission.Builder{ + Builder: fv1.Builder{ Image: "yyy", Command: "zzz", }, @@ -215,7 +215,7 @@ func environmentTests(crdClient *rest.RESTClient) { log.Panicf("Didn't get watch event") } case ev := <-wi.ResultChan(): - obj, ok := ev.Object.(*Environment) + obj, ok := ev.Object.(*fv1.Environment) if !ok { log.Panicf("Can't cast to Environment") } @@ -230,20 +230,20 @@ func environmentTests(crdClient *rest.RESTClient) { func httpTriggerTests(crdClient *rest.RESTClient) { // sample httpTrigger object - httpTrigger := &HTTPTrigger{ + httpTrigger := &fv1.HTTPTrigger{ TypeMeta: metav1.TypeMeta{ Kind: "HTTPTrigger", - APIVersion: "fission.io/v1", + APIVersion: "fv1.io/v1", }, Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: metav1.NamespaceDefault, }, - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ RelativeURL: "/hi", Method: "GET", - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: "hello", }, }, @@ -307,7 +307,7 @@ func httpTriggerTests(crdClient *rest.RESTClient) { log.Panicf("Didn't get watch event") } case ev := <-wi.ResultChan(): - obj, ok := ev.Object.(*HTTPTrigger) + obj, ok := ev.Object.(*fv1.HTTPTrigger) if !ok { log.Panicf("Can't cast to HTTPTrigger") } @@ -322,23 +322,23 @@ func httpTriggerTests(crdClient *rest.RESTClient) { func kubernetesWatchTriggerTests(crdClient *rest.RESTClient) { // sample kubernetesWatchTrigger object - kubernetesWatchTrigger := &KubernetesWatchTrigger{ + kubernetesWatchTrigger := &fv1.KubernetesWatchTrigger{ TypeMeta: metav1.TypeMeta{ Kind: "KubernetesWatchTrigger", - APIVersion: "fission.io/v1", + APIVersion: "fv1.io/v1", }, Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: metav1.NamespaceDefault, }, - Spec: fission.KubernetesWatchTriggerSpec{ + Spec: fv1.KubernetesWatchTriggerSpec{ Namespace: "foo", Type: "pod", LabelSelector: map[string]string{ "x": "y", }, - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: "foo", }, }, @@ -402,7 +402,7 @@ func kubernetesWatchTriggerTests(crdClient *rest.RESTClient) { log.Panicf("Didn't get watch event") } case ev := <-wi.ResultChan(): - obj, ok := ev.Object.(*KubernetesWatchTrigger) + obj, ok := ev.Object.(*fv1.KubernetesWatchTrigger) if !ok { log.Panicf("Can't cast to KubernetesWatchTrigger") } diff --git a/crd/environment.go b/pkg/crd/environment.go similarity index 76% rename from crd/environment.go rename to pkg/crd/environment.go index feddd2b8..ce36d5d1 100644 --- a/crd/environment.go +++ b/pkg/crd/environment.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( EnvironmentInterface interface { - Create(*Environment) (*Environment, error) - Get(name string) (*Environment, error) - Update(*Environment) (*Environment, error) + Create(*fv1.Environment) (*fv1.Environment, error) + Get(name string) (*fv1.Environment, error) + Update(*fv1.Environment) (*fv1.Environment, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*EnvironmentList, error) + List(opts metav1.ListOptions) (*fv1.EnvironmentList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeEnvironmentInterface(crdClient *rest.RESTClient, namespace string) Envi } } -func (ec *environmentClient) Create(e *Environment) (*Environment, error) { - var result Environment +func (ec *environmentClient) Create(e *fv1.Environment) (*fv1.Environment, error) { + var result fv1.Environment err := ec.client.Post(). Resource("environments"). Namespace(ec.namespace). @@ -59,8 +61,8 @@ func (ec *environmentClient) Create(e *Environment) (*Environment, error) { return &result, nil } -func (ec *environmentClient) Get(name string) (*Environment, error) { - var result Environment +func (ec *environmentClient) Get(name string) (*fv1.Environment, error) { + var result fv1.Environment err := ec.client.Get(). Resource("environments"). Namespace(ec.namespace). @@ -72,8 +74,8 @@ func (ec *environmentClient) Get(name string) (*Environment, error) { return &result, nil } -func (ec *environmentClient) Update(e *Environment) (*Environment, error) { - var result Environment +func (ec *environmentClient) Update(e *fv1.Environment) (*fv1.Environment, error) { + var result fv1.Environment err := ec.client.Put(). Resource("environments"). Namespace(ec.namespace). @@ -96,8 +98,8 @@ func (ec *environmentClient) Delete(name string, opts *metav1.DeleteOptions) err Error() } -func (ec *environmentClient) List(opts metav1.ListOptions) (*EnvironmentList, error) { - var result EnvironmentList +func (ec *environmentClient) List(opts metav1.ListOptions) (*fv1.EnvironmentList, error) { + var result fv1.EnvironmentList err := ec.client.Get(). Namespace(ec.namespace). Resource("environments"). diff --git a/crd/function.go b/pkg/crd/function.go similarity index 78% rename from crd/function.go rename to pkg/crd/function.go index 447cb03e..8e296e2e 100644 --- a/crd/function.go +++ b/pkg/crd/function.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( FunctionInterface interface { - Create(*Function) (*Function, error) - Get(name string) (*Function, error) - Update(*Function) (*Function, error) + Create(*fv1.Function) (*fv1.Function, error) + Get(name string) (*fv1.Function, error) + Update(*fv1.Function) (*fv1.Function, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*FunctionList, error) + List(opts metav1.ListOptions) (*fv1.FunctionList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeFunctionInterface(crdClient *rest.RESTClient, namespace string) Functio } } -func (fc *functionClient) Create(f *Function) (*Function, error) { - var result Function +func (fc *functionClient) Create(f *fv1.Function) (*fv1.Function, error) { + var result fv1.Function err := fc.client.Post(). Resource("functions"). Namespace(fc.namespace). @@ -59,8 +61,8 @@ func (fc *functionClient) Create(f *Function) (*Function, error) { return &result, nil } -func (fc *functionClient) Get(name string) (*Function, error) { - var result Function +func (fc *functionClient) Get(name string) (*fv1.Function, error) { + var result fv1.Function err := fc.client.Get(). Resource("functions"). Namespace(fc.namespace). @@ -72,8 +74,8 @@ func (fc *functionClient) Get(name string) (*Function, error) { return &result, nil } -func (fc *functionClient) Update(f *Function) (*Function, error) { - var result Function +func (fc *functionClient) Update(f *fv1.Function) (*fv1.Function, error) { + var result fv1.Function err := fc.client.Put(). Resource("functions"). Namespace(fc.namespace). @@ -96,8 +98,8 @@ func (fc *functionClient) Delete(name string, opts *metav1.DeleteOptions) error Error() } -func (fc *functionClient) List(opts metav1.ListOptions) (*FunctionList, error) { - var result FunctionList +func (fc *functionClient) List(opts metav1.ListOptions) (*fv1.FunctionList, error) { + var result fv1.FunctionList err := fc.client.Get(). Namespace(fc.namespace). Resource("functions"). diff --git a/crd/httptrigger.go b/pkg/crd/httptrigger.go similarity index 76% rename from crd/httptrigger.go rename to pkg/crd/httptrigger.go index 2b10cef2..1096bb18 100644 --- a/crd/httptrigger.go +++ b/pkg/crd/httptrigger.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( HTTPTriggerInterface interface { - Create(*HTTPTrigger) (*HTTPTrigger, error) - Get(name string) (*HTTPTrigger, error) - Update(*HTTPTrigger) (*HTTPTrigger, error) + Create(*fv1.HTTPTrigger) (*fv1.HTTPTrigger, error) + Get(name string) (*fv1.HTTPTrigger, error) + Update(*fv1.HTTPTrigger) (*fv1.HTTPTrigger, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*HTTPTriggerList, error) + List(opts metav1.ListOptions) (*fv1.HTTPTriggerList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeHTTPTriggerInterface(crdClient *rest.RESTClient, namespace string) HTTP } } -func (c *httpTriggerClient) Create(obj *HTTPTrigger) (*HTTPTrigger, error) { - var result HTTPTrigger +func (c *httpTriggerClient) Create(obj *fv1.HTTPTrigger) (*fv1.HTTPTrigger, error) { + var result fv1.HTTPTrigger err := c.client.Post(). Resource("httptriggers"). Namespace(c.namespace). @@ -59,8 +61,8 @@ func (c *httpTriggerClient) Create(obj *HTTPTrigger) (*HTTPTrigger, error) { return &result, nil } -func (c *httpTriggerClient) Get(name string) (*HTTPTrigger, error) { - var result HTTPTrigger +func (c *httpTriggerClient) Get(name string) (*fv1.HTTPTrigger, error) { + var result fv1.HTTPTrigger err := c.client.Get(). Resource("httptriggers"). Namespace(c.namespace). @@ -72,8 +74,8 @@ func (c *httpTriggerClient) Get(name string) (*HTTPTrigger, error) { return &result, nil } -func (c *httpTriggerClient) Update(obj *HTTPTrigger) (*HTTPTrigger, error) { - var result HTTPTrigger +func (c *httpTriggerClient) Update(obj *fv1.HTTPTrigger) (*fv1.HTTPTrigger, error) { + var result fv1.HTTPTrigger err := c.client.Put(). Resource("httptriggers"). Namespace(c.namespace). @@ -96,8 +98,8 @@ func (c *httpTriggerClient) Delete(name string, opts *metav1.DeleteOptions) erro Error() } -func (c *httpTriggerClient) List(opts metav1.ListOptions) (*HTTPTriggerList, error) { - var result HTTPTriggerList +func (c *httpTriggerClient) List(opts metav1.ListOptions) (*fv1.HTTPTriggerList, error) { + var result fv1.HTTPTriggerList err := c.client.Get(). Namespace(c.namespace). Resource("httptriggers"). diff --git a/crd/key.go b/pkg/crd/key.go similarity index 100% rename from crd/key.go rename to pkg/crd/key.go diff --git a/crd/kubernetesWatchTrigger.go b/pkg/crd/kubernetesWatchTrigger.go similarity index 74% rename from crd/kubernetesWatchTrigger.go rename to pkg/crd/kubernetesWatchTrigger.go index 84bb9226..12187c83 100644 --- a/crd/kubernetesWatchTrigger.go +++ b/pkg/crd/kubernetesWatchTrigger.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( KubernetesWatchTriggerInterface interface { - Create(*KubernetesWatchTrigger) (*KubernetesWatchTrigger, error) - Get(name string) (*KubernetesWatchTrigger, error) - Update(*KubernetesWatchTrigger) (*KubernetesWatchTrigger, error) + Create(*fv1.KubernetesWatchTrigger) (*fv1.KubernetesWatchTrigger, error) + Get(name string) (*fv1.KubernetesWatchTrigger, error) + Update(*fv1.KubernetesWatchTrigger) (*fv1.KubernetesWatchTrigger, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*KubernetesWatchTriggerList, error) + List(opts metav1.ListOptions) (*fv1.KubernetesWatchTriggerList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeKubernetesWatchTriggerInterface(crdClient *rest.RESTClient, namespace s } } -func (c *kubernetesWatchTriggerClient) Create(obj *KubernetesWatchTrigger) (*KubernetesWatchTrigger, error) { - var result KubernetesWatchTrigger +func (c *kubernetesWatchTriggerClient) Create(obj *fv1.KubernetesWatchTrigger) (*fv1.KubernetesWatchTrigger, error) { + var result fv1.KubernetesWatchTrigger err := c.client.Post(). Resource("kuberneteswatchtriggers"). Namespace(c.namespace). @@ -59,8 +61,8 @@ func (c *kubernetesWatchTriggerClient) Create(obj *KubernetesWatchTrigger) (*Kub return &result, nil } -func (c *kubernetesWatchTriggerClient) Get(name string) (*KubernetesWatchTrigger, error) { - var result KubernetesWatchTrigger +func (c *kubernetesWatchTriggerClient) Get(name string) (*fv1.KubernetesWatchTrigger, error) { + var result fv1.KubernetesWatchTrigger err := c.client.Get(). Resource("kuberneteswatchtriggers"). Namespace(c.namespace). @@ -72,8 +74,8 @@ func (c *kubernetesWatchTriggerClient) Get(name string) (*KubernetesWatchTrigger return &result, nil } -func (c *kubernetesWatchTriggerClient) Update(obj *KubernetesWatchTrigger) (*KubernetesWatchTrigger, error) { - var result KubernetesWatchTrigger +func (c *kubernetesWatchTriggerClient) Update(obj *fv1.KubernetesWatchTrigger) (*fv1.KubernetesWatchTrigger, error) { + var result fv1.KubernetesWatchTrigger err := c.client.Put(). Resource("kuberneteswatchtriggers"). Namespace(c.namespace). @@ -96,8 +98,8 @@ func (c *kubernetesWatchTriggerClient) Delete(name string, opts *metav1.DeleteOp Error() } -func (c *kubernetesWatchTriggerClient) List(opts metav1.ListOptions) (*KubernetesWatchTriggerList, error) { - var result KubernetesWatchTriggerList +func (c *kubernetesWatchTriggerClient) List(opts metav1.ListOptions) (*fv1.KubernetesWatchTriggerList, error) { + var result fv1.KubernetesWatchTriggerList err := c.client.Get(). Namespace(c.namespace). Resource("kuberneteswatchtriggers"). diff --git a/crd/messagequeuetrigger.go b/pkg/crd/messagequeuetrigger.go similarity index 75% rename from crd/messagequeuetrigger.go rename to pkg/crd/messagequeuetrigger.go index 8d84a124..df447cdf 100644 --- a/crd/messagequeuetrigger.go +++ b/pkg/crd/messagequeuetrigger.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( MessageQueueTriggerInterface interface { - Create(*MessageQueueTrigger) (*MessageQueueTrigger, error) - Get(name string) (*MessageQueueTrigger, error) - Update(*MessageQueueTrigger) (*MessageQueueTrigger, error) + Create(*fv1.MessageQueueTrigger) (*fv1.MessageQueueTrigger, error) + Get(name string) (*fv1.MessageQueueTrigger, error) + Update(*fv1.MessageQueueTrigger) (*fv1.MessageQueueTrigger, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*MessageQueueTriggerList, error) + List(opts metav1.ListOptions) (*fv1.MessageQueueTriggerList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeMessageQueueTriggerInterface(crdClient *rest.RESTClient, namespace stri } } -func (fc *messageQueueTriggerClient) Create(f *MessageQueueTrigger) (*MessageQueueTrigger, error) { - var result MessageQueueTrigger +func (fc *messageQueueTriggerClient) Create(f *fv1.MessageQueueTrigger) (*fv1.MessageQueueTrigger, error) { + var result fv1.MessageQueueTrigger err := fc.client.Post(). Resource("messagequeuetriggers"). Namespace(fc.namespace). @@ -59,8 +61,8 @@ func (fc *messageQueueTriggerClient) Create(f *MessageQueueTrigger) (*MessageQue return &result, nil } -func (fc *messageQueueTriggerClient) Get(name string) (*MessageQueueTrigger, error) { - var result MessageQueueTrigger +func (fc *messageQueueTriggerClient) Get(name string) (*fv1.MessageQueueTrigger, error) { + var result fv1.MessageQueueTrigger err := fc.client.Get(). Resource("messagequeuetriggers"). Namespace(fc.namespace). @@ -72,8 +74,8 @@ func (fc *messageQueueTriggerClient) Get(name string) (*MessageQueueTrigger, err return &result, nil } -func (fc *messageQueueTriggerClient) Update(f *MessageQueueTrigger) (*MessageQueueTrigger, error) { - var result MessageQueueTrigger +func (fc *messageQueueTriggerClient) Update(f *fv1.MessageQueueTrigger) (*fv1.MessageQueueTrigger, error) { + var result fv1.MessageQueueTrigger err := fc.client.Put(). Resource("messagequeuetriggers"). Namespace(fc.namespace). @@ -96,8 +98,8 @@ func (fc *messageQueueTriggerClient) Delete(name string, opts *metav1.DeleteOpti Error() } -func (fc *messageQueueTriggerClient) List(opts metav1.ListOptions) (*MessageQueueTriggerList, error) { - var result MessageQueueTriggerList +func (fc *messageQueueTriggerClient) List(opts metav1.ListOptions) (*fv1.MessageQueueTriggerList, error) { + var result fv1.MessageQueueTriggerList err := fc.client.Get(). Namespace(fc.namespace). Resource("messagequeuetriggers"). diff --git a/crd/package.go b/pkg/crd/package.go similarity index 78% rename from crd/package.go rename to pkg/crd/package.go index 8db5541e..40d0155d 100644 --- a/crd/package.go +++ b/pkg/crd/package.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( PackageInterface interface { - Create(*Package) (*Package, error) - Get(name string) (*Package, error) - Update(*Package) (*Package, error) + Create(*fv1.Package) (*fv1.Package, error) + Get(name string) (*fv1.Package, error) + Update(*fv1.Package) (*fv1.Package, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*PackageList, error) + List(opts metav1.ListOptions) (*fv1.PackageList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakePackageInterface(crdClient *rest.RESTClient, namespace string) PackageI } } -func (c *packageClient) Create(f *Package) (*Package, error) { - var result Package +func (c *packageClient) Create(f *fv1.Package) (*fv1.Package, error) { + var result fv1.Package err := c.client.Post(). Resource("packages"). Namespace(c.namespace). @@ -59,8 +61,8 @@ func (c *packageClient) Create(f *Package) (*Package, error) { return &result, nil } -func (c *packageClient) Get(name string) (*Package, error) { - var result Package +func (c *packageClient) Get(name string) (*fv1.Package, error) { + var result fv1.Package err := c.client.Get(). Resource("packages"). Namespace(c.namespace). @@ -72,8 +74,8 @@ func (c *packageClient) Get(name string) (*Package, error) { return &result, nil } -func (c *packageClient) Update(f *Package) (*Package, error) { - var result Package +func (c *packageClient) Update(f *fv1.Package) (*fv1.Package, error) { + var result fv1.Package err := c.client.Put(). Resource("packages"). Namespace(c.namespace). @@ -96,8 +98,8 @@ func (c *packageClient) Delete(name string, opts *metav1.DeleteOptions) error { Error() } -func (c *packageClient) List(opts metav1.ListOptions) (*PackageList, error) { - var result PackageList +func (c *packageClient) List(opts metav1.ListOptions) (*fv1.PackageList, error) { + var result fv1.PackageList err := c.client.Get(). Namespace(c.namespace). Resource("packages"). diff --git a/crd/recorder.go b/pkg/crd/recorder.go similarity index 78% rename from crd/recorder.go rename to pkg/crd/recorder.go index 434a54ae..b1797306 100644 --- a/crd/recorder.go +++ b/pkg/crd/recorder.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( RecorderInterface interface { - Create(*Recorder) (*Recorder, error) - Get(name string) (*Recorder, error) - Update(*Recorder) (*Recorder, error) + Create(*fv1.Recorder) (*fv1.Recorder, error) + Get(name string) (*fv1.Recorder, error) + Update(*fv1.Recorder) (*fv1.Recorder, error) Delete(name string, opts *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*RecorderList, error) + List(opts metav1.ListOptions) (*fv1.RecorderList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeRecorderInterface(crdClient *rest.RESTClient, namespace string) Recorde } } -func (rc *recorderClient) Create(r *Recorder) (*Recorder, error) { - var result Recorder +func (rc *recorderClient) Create(r *fv1.Recorder) (*fv1.Recorder, error) { + var result fv1.Recorder err := rc.client.Post(). Resource("recorders"). Namespace("default"). @@ -59,8 +61,8 @@ func (rc *recorderClient) Create(r *Recorder) (*Recorder, error) { return &result, nil } -func (rc *recorderClient) Get(name string) (*Recorder, error) { - var result Recorder +func (rc *recorderClient) Get(name string) (*fv1.Recorder, error) { + var result fv1.Recorder err := rc.client.Get(). Resource("recorders"). Namespace(rc.namespace). @@ -72,8 +74,8 @@ func (rc *recorderClient) Get(name string) (*Recorder, error) { return &result, nil } -func (rc *recorderClient) Update(r *Recorder) (*Recorder, error) { - var result Recorder +func (rc *recorderClient) Update(r *fv1.Recorder) (*fv1.Recorder, error) { + var result fv1.Recorder err := rc.client.Put(). Resource("recorders"). Namespace(rc.namespace). @@ -96,8 +98,8 @@ func (rc *recorderClient) Delete(name string, opts *metav1.DeleteOptions) error Error() } -func (rc *recorderClient) List(opts metav1.ListOptions) (*RecorderList, error) { - var result RecorderList +func (rc *recorderClient) List(opts metav1.ListOptions) (*fv1.RecorderList, error) { + var result fv1.RecorderList err := rc.client.Get(). Namespace(rc.namespace). Resource("recorders"). diff --git a/crd/timetrigger.go b/pkg/crd/timetrigger.go similarity index 76% rename from crd/timetrigger.go rename to pkg/crd/timetrigger.go index 59850dfe..9f2a970e 100644 --- a/crd/timetrigger.go +++ b/pkg/crd/timetrigger.go @@ -21,15 +21,17 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( TimeTriggerInterface interface { - Create(*TimeTrigger) (*TimeTrigger, error) - Get(name string) (*TimeTrigger, error) - Update(*TimeTrigger) (*TimeTrigger, error) + Create(*fv1.TimeTrigger) (*fv1.TimeTrigger, error) + Get(name string) (*fv1.TimeTrigger, error) + Update(*fv1.TimeTrigger) (*fv1.TimeTrigger, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*TimeTriggerList, error) + List(opts metav1.ListOptions) (*fv1.TimeTriggerList, error) Watch(opts metav1.ListOptions) (watch.Interface, error) } @@ -46,8 +48,8 @@ func MakeTimeTriggerInterface(crdClient *rest.RESTClient, namespace string) Time } } -func (fc *timeTriggerClient) Create(f *TimeTrigger) (*TimeTrigger, error) { - var result TimeTrigger +func (fc *timeTriggerClient) Create(f *fv1.TimeTrigger) (*fv1.TimeTrigger, error) { + var result fv1.TimeTrigger err := fc.client.Post(). Resource("timetriggers"). Namespace(fc.namespace). @@ -59,8 +61,8 @@ func (fc *timeTriggerClient) Create(f *TimeTrigger) (*TimeTrigger, error) { return &result, nil } -func (fc *timeTriggerClient) Get(name string) (*TimeTrigger, error) { - var result TimeTrigger +func (fc *timeTriggerClient) Get(name string) (*fv1.TimeTrigger, error) { + var result fv1.TimeTrigger err := fc.client.Get(). Resource("timetriggers"). Namespace(fc.namespace). @@ -72,8 +74,8 @@ func (fc *timeTriggerClient) Get(name string) (*TimeTrigger, error) { return &result, nil } -func (fc *timeTriggerClient) Update(f *TimeTrigger) (*TimeTrigger, error) { - var result TimeTrigger +func (fc *timeTriggerClient) Update(f *fv1.TimeTrigger) (*fv1.TimeTrigger, error) { + var result fv1.TimeTrigger err := fc.client.Put(). Resource("timetriggers"). Namespace(fc.namespace). @@ -96,8 +98,8 @@ func (fc *timeTriggerClient) Delete(name string, opts *metav1.DeleteOptions) err Error() } -func (fc *timeTriggerClient) List(opts metav1.ListOptions) (*TimeTriggerList, error) { - var result TimeTriggerList +func (fc *timeTriggerClient) List(opts metav1.ListOptions) (*fv1.TimeTriggerList, error) { + var result fv1.TimeTriggerList err := fc.client.Get(). Namespace(fc.namespace). Resource("timetriggers"). diff --git a/error.go b/pkg/error/httperror.go similarity index 77% rename from error.go rename to pkg/error/httperror.go index 0d11c4d1..a4c59ebb 100644 --- a/error.go +++ b/pkg/error/httperror.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fission +package error import ( "fmt" @@ -23,6 +23,16 @@ import ( "strings" ) +type ( + // Errors returned by the Fission API. + Error struct { + Code errorCode `json:"code"` + Message string `json:"message"` + } + + errorCode int +) + func (err Error) Error() string { return fmt.Sprintf("%v - %v", err.Description(), err.Message) } @@ -98,3 +108,29 @@ func (err Error) Description() string { } return errorDescriptions[idx] } + +const ( + ErrorInternal = iota + + ErrorNotAuthorized + ErrorNotFound + ErrorNameExists + ErrorInvalidArgument + ErrorNoSpace + ErrorNotImplmented + ErrorChecksumFail + ErrorSizeLimitExceeded +) + +// must match order and len of the above const +var errorDescriptions = []string{ + "Internal error", + "Not authorized", + "Resource not found", + "Resource exists", + "Invalid argument", + "No space", + "Not implemented", + "Checksum verification failed", + "Size limit exceeded", +} diff --git a/executor/api.go b/pkg/executor/api.go similarity index 96% rename from executor/api.go rename to pkg/executor/api.go index 835ee49f..71b95e2e 100644 --- a/executor/api.go +++ b/pkg/executor/api.go @@ -24,12 +24,13 @@ import ( "net/http" "strings" + "github.com/fission/fission/pkg/utils" "github.com/gorilla/mux" "go.opencensus.io/plugin/ochttp" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" + ferror "github.com/fission/fission/pkg/error" ) func (executor *Executor) getServiceForFunctionApi(w http.ResponseWriter, r *http.Request) { @@ -49,7 +50,7 @@ func (executor *Executor) getServiceForFunctionApi(w http.ResponseWriter, r *htt serviceName, err := executor.getServiceForFunction(r.Context(), &m) if err != nil { - code, msg := fission.GetHTTPError(err) + code, msg := ferror.GetHTTPError(err) executor.logger.Error("error getting service for function", zap.Error(err), zap.String("function", m.Name), @@ -140,7 +141,7 @@ func (executor *Executor) Serve(port int) { defer cancel() executor.ndm.Run(ctx) executor.gpm.Run(ctx) - r.Use(fission.LoggingMiddleware(executor.logger)) + r.Use(utils.LoggingMiddleware(executor.logger)) err := http.ListenAndServe(address, &ochttp.Handler{ Handler: r, // Propagation: &b3.HTTPFormat{}, diff --git a/executor/client/client.go b/pkg/executor/client/client.go similarity index 95% rename from executor/client/client.go rename to pkg/executor/client/client.go index ccd855e1..fa48edfa 100644 --- a/executor/client/client.go +++ b/pkg/executor/client/client.go @@ -32,7 +32,7 @@ import ( "golang.org/x/net/context/ctxhttp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" + ferror "github.com/fission/fission/pkg/error" ) type Client struct { @@ -72,7 +72,7 @@ func (c *Client) GetServiceForFunction(ctx context.Context, metadata *metav1.Obj defer resp.Body.Close() if resp.StatusCode != 200 { - return "", fission.MakeErrorFromHTTP(resp) + return "", ferror.MakeErrorFromHTTP(resp) } svcName, err := ioutil.ReadAll(resp.Body) @@ -120,7 +120,7 @@ func (c *Client) _tapService(serviceUrlStr string) error { } defer resp.Body.Close() if resp.StatusCode != 200 { - return fission.MakeErrorFromHTTP(resp) + return ferror.MakeErrorFromHTTP(resp) } return nil } diff --git a/executor/executor.go b/pkg/executor/executor.go similarity index 93% rename from executor/executor.go rename to pkg/executor/executor.go index 2a8fcaba..3931f266 100644 --- a/executor/executor.go +++ b/pkg/executor/executor.go @@ -30,13 +30,14 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" - "github.com/fission/fission/executor/fscache" - "github.com/fission/fission/executor/newdeploy" - "github.com/fission/fission/executor/poolmgr" - "github.com/fission/fission/executor/reaper" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/fscache" + "github.com/fission/fission/pkg/executor/newdeploy" + "github.com/fission/fission/pkg/executor/poolmgr" + "github.com/fission/fission/pkg/executor/reaper" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" + "github.com/fission/fission/pkg/utils" ) type ( @@ -137,7 +138,7 @@ func (executor *Executor) serveCreateFuncServices() { } } -func (executor *Executor) getFunctionExecutorType(meta *metav1.ObjectMeta) (fission.ExecutorType, error) { +func (executor *Executor) getFunctionExecutorType(meta *metav1.ObjectMeta) (fv1.ExecutorType, error) { fn, err := executor.fissionClient.Functions(meta.Namespace).Get(meta.Name) if err != nil { return "", err @@ -159,7 +160,7 @@ func (executor *Executor) createServiceForFunction(ctx context.Context, meta *me var fsvcErr error switch executorType { - case fission.ExecutorTypeNewdeploy: + case fv1.ExecutorTypeNewdeploy: fsvc, fsvcErr = executor.ndm.GetFuncSvc(ctx, meta) default: fsvc, fsvcErr = executor.gpm.GetFuncSvc(ctx, meta) @@ -206,7 +207,7 @@ func serveMetric(logger *zap.Logger) { // deploymgr and potential future executor types func StartExecutor(logger *zap.Logger, fissionNamespace string, functionNamespace string, envBuilderNamespace string, port int) error { // setup a signal handler for SIGTERM - fission.SetupStackTraceHandler() + utils.SetupStackTraceHandler() fissionClient, kubernetesClient, _, err := crd.MakeFissionClient() diff --git a/executor/executor_test.go b/pkg/executor/executor_test.go similarity index 86% rename from executor/executor_test.go rename to pkg/executor/executor_test.go index e9dfe583..0f32e48d 100644 --- a/executor/executor_test.go +++ b/pkg/executor/executor_test.go @@ -40,9 +40,9 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/executor/client" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/client" ) func panicIf(err error) { @@ -53,7 +53,7 @@ func panicIf(err error) { // return the number of pods in the given namespace matching the given labels func countPods(kubeClient *kubernetes.Clientset, ns string, labelz map[string]string) int { - pods, err := kubeClient.Pods(ns).List(metav1.ListOptions{ + pods, err := kubeClient.CoreV1().Pods(ns).List(metav1.ListOptions{ LabelSelector: labels.Set(labelz).AsSelector().String(), }) if err != nil { @@ -63,7 +63,7 @@ func countPods(kubeClient *kubernetes.Clientset, ns string, labelz map[string]st } func createTestNamespace(kubeClient *kubernetes.Clientset, ns string) { - _, err := kubeClient.Namespaces().Create(&apiv1.Namespace{ + _, err := kubeClient.CoreV1().Namespaces().Create(&apiv1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: ns, }, @@ -76,7 +76,7 @@ func createTestNamespace(kubeClient *kubernetes.Clientset, ns string) { // create a nodeport service func createSvc(kubeClient *kubernetes.Clientset, ns string, name string, targetPort int, nodePort int32, labels map[string]string) *apiv1.Service { - svc, err := kubeClient.Services(ns).Create(&apiv1.Service{ + svc, err := kubeClient.CoreV1().Services(ns).Create(&apiv1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: name, }, @@ -136,10 +136,10 @@ func TestExecutor(t *testing.T) { // create the test's namespaces createTestNamespace(kubeClient, fissionNs) - defer kubeClient.Namespaces().Delete(fissionNs, nil) + defer kubeClient.CoreV1().Namespaces().Delete(fissionNs, nil) createTestNamespace(kubeClient, functionNs) - defer kubeClient.Namespaces().Delete(functionNs, nil) + defer kubeClient.CoreV1().Namespaces().Delete(functionNs, nil) logger, err := zap.NewDevelopment() panicIf(err) @@ -156,17 +156,17 @@ func TestExecutor(t *testing.T) { } // create an env on the cluster - env, err := fissionClient.Environments(fissionNs).Create(&crd.Environment{ + env, err := fissionClient.Environments(fissionNs).Create(&fv1.Environment{ Metadata: metav1.ObjectMeta{ Name: "nodejs", Namespace: fissionNs, }, - Spec: fission.EnvironmentSpec{ + Spec: fv1.EnvironmentSpec{ Version: 1, - Runtime: fission.Runtime{ + Runtime: fv1.Runtime{ Image: "fission/node-env", }, - Builder: fission.Builder{}, + Builder: fv1.Builder{}, }, }) if err != nil { @@ -188,23 +188,23 @@ func TestExecutor(t *testing.T) { // waitForPool(functionNs, "nodejs") time.Sleep(6 * time.Second) - envRef := fission.EnvironmentReference{ + envRef := fv1.EnvironmentReference{ Namespace: env.Metadata.Namespace, Name: env.Metadata.Name, } - deployment := fission.Archive{ - Type: fission.ArchiveTypeLiteral, + deployment := fv1.Archive{ + Type: fv1.ArchiveTypeLiteral, Literal: []byte(`module.exports = async function(context) { return { status: 200, body: "Hello, world!\n" }; }`), } // create a package - p := &crd.Package{ + p := &fv1.Package{ Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: fissionNs, }, - Spec: fission.PackageSpec{ + Spec: fv1.PackageSpec{ Environment: envRef, Deployment: deployment, }, @@ -215,15 +215,15 @@ func TestExecutor(t *testing.T) { } // create a function - f := &crd.Function{ + f := &fv1.Function{ Metadata: metav1.ObjectMeta{ Name: "hello", Namespace: fissionNs, }, - Spec: fission.FunctionSpec{ + Spec: fv1.FunctionSpec{ Environment: envRef, - Package: fission.FunctionPackageRef{ - PackageRef: fission.PackageRef{ + Package: fv1.FunctionPackageRef{ + PackageRef: fv1.PackageRef{ Namespace: p.Metadata.Namespace, Name: p.Metadata.Name, ResourceVersion: p.Metadata.ResourceVersion, @@ -240,11 +240,11 @@ func TestExecutor(t *testing.T) { labels := map[string]string{"functionName": f.Metadata.Name} var fetcherPort int32 = 30001 fetcherSvc := createSvc(kubeClient, functionNs, fmt.Sprintf("%v-%v", f.Metadata.Name, "fetcher"), 8000, fetcherPort, labels) - defer kubeClient.Services(functionNs).Delete(fetcherSvc.ObjectMeta.Name, nil) + defer kubeClient.CoreV1().Services(functionNs).Delete(fetcherSvc.ObjectMeta.Name, nil) var funcSvcPort int32 = 30002 functionSvc := createSvc(kubeClient, functionNs, f.Metadata.Name, 8888, funcSvcPort, labels) - defer kubeClient.Services(functionNs).Delete(functionSvc.ObjectMeta.Name, nil) + defer kubeClient.CoreV1().Services(functionNs).Delete(functionSvc.ObjectMeta.Name, nil) // the main test: get a service for a given function t1 := time.Now() diff --git a/executor/fscache/functionServiceCache.go b/pkg/executor/fscache/functionServiceCache.go similarity index 94% rename from executor/fscache/functionServiceCache.go rename to pkg/executor/fscache/functionServiceCache.go index 5cd95b9b..0d0dcb43 100644 --- a/executor/fscache/functionServiceCache.go +++ b/pkg/executor/fscache/functionServiceCache.go @@ -26,9 +26,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" + "github.com/fission/fission/pkg/crd" + ferror "github.com/fission/fission/pkg/error" ) type fscRequestType int @@ -49,7 +50,7 @@ type ( FuncSvc struct { Name string // Name of object Function *metav1.ObjectMeta // function this pod/service is for - Environment *crd.Environment // function's environment + Environment *fv1.Environment // function's environment Address string // Host:Port or IP:Port that the function's service can be reached at. KubernetesObjects []apiv1.ObjectReference // Kubernetes Objects (within the function namespace) Executor executorType @@ -81,15 +82,15 @@ type ( ) func IsNotFoundError(err error) bool { - if fe, ok := err.(fission.Error); ok { - return fe.Code == fission.ErrorNotFound + if fe, ok := err.(ferror.Error); ok { + return fe.Code == ferror.ErrorNotFound } return false } func IsNameExistError(err error) bool { - if fe, ok := err.(fission.Error); ok { - return fe.Code == fission.ErrorNameExists + if fe, ok := err.(ferror.Error); ok { + return fe.Code == ferror.ErrorNameExists } return false } diff --git a/executor/fscache/functionServiceCache_test.go b/pkg/executor/fscache/functionServiceCache_test.go similarity index 90% rename from executor/fscache/functionServiceCache_test.go rename to pkg/executor/fscache/functionServiceCache_test.go index 38caa5ac..1f3deb89 100644 --- a/executor/fscache/functionServiceCache_test.go +++ b/pkg/executor/fscache/functionServiceCache_test.go @@ -9,8 +9,7 @@ import ( apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) func panicIf(err error) { @@ -51,17 +50,17 @@ func TestFunctionServiceCache(t *testing.T) { Name: "foo", UID: "1212", }, - Environment: &crd.Environment{ + Environment: &fv1.Environment{ Metadata: metav1.ObjectMeta{ Name: "foo-env", UID: "2323", }, - Spec: fission.EnvironmentSpec{ + Spec: fv1.EnvironmentSpec{ Version: 1, - Runtime: fission.Runtime{ + Runtime: fv1.Runtime{ Image: "fission/foo-env", }, - Builder: fission.Builder{}, + Builder: fv1.Builder{}, }, }, Address: "xxx", @@ -69,7 +68,7 @@ func TestFunctionServiceCache(t *testing.T) { Ctime: now, Atime: now, } - _, err := fsc.Add(*fsvc) + _, err = fsc.Add(*fsvc) if err != nil { fsc.Log() log.Panicf("Failed to add fsvc: %v", err) diff --git a/executor/fscache/metrics.go b/pkg/executor/fscache/metrics.go similarity index 100% rename from executor/fscache/metrics.go rename to pkg/executor/fscache/metrics.go diff --git a/executor/newdeploy/newdeploy.go b/pkg/executor/newdeploy/newdeploy.go similarity index 91% rename from executor/newdeploy/newdeploy.go rename to pkg/executor/newdeploy/newdeploy.go index 9815fbf8..c723932c 100644 --- a/executor/newdeploy/newdeploy.go +++ b/pkg/executor/newdeploy/newdeploy.go @@ -21,6 +21,9 @@ import ( "fmt" "time" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" + multierror "github.com/hashicorp/go-multierror" "go.uber.org/zap" asv1 "k8s.io/api/autoscaling/v1" apiv1 "k8s.io/api/core/v1" @@ -30,10 +33,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/executor/util" - multierror "github.com/hashicorp/go-multierror" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/executor/util" ) const ( @@ -41,7 +42,7 @@ const ( DeploymentVersion = "extensions/v1beta1" ) -func (deploy *NewDeploy) createOrGetDeployment(fn *crd.Function, env *crd.Environment, +func (deploy *NewDeploy) createOrGetDeployment(fn *fv1.Function, env *fv1.Environment, deployName string, deployLabels map[string]string, deployNamespace string, firstcreate bool) (*v1beta1.Deployment, error) { minScale := int32(fn.Spec.InvokeStrategy.ExecutionStrategy.MinScale) @@ -102,13 +103,13 @@ func (deploy *NewDeploy) createOrGetDeployment(fn *crd.Function, env *crd.Enviro } -func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *crd.Function) error { +func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function) error { // create fetcher SA in this ns, if not already created err := deploy.fetcherConfig.SetupServiceAccount(deploy.kubernetesClient, deployNamespace, fn.Metadata) if err != nil { deploy.logger.Error("error creating fission fetcher service account for function", zap.Error(err), - zap.String("service_account_name", fission.FissionFetcherSA), + zap.String("service_account_name", types.FissionFetcherSA), zap.String("service_account_namespace", deployNamespace), zap.String("function_name", fn.Metadata.Name), zap.String("function_namespace", fn.Metadata.Namespace)) @@ -116,22 +117,22 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *crd.Function) } // create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns - err = fission.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fission.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, fission.PackageGetterCR, fission.ClusterRole, fission.FissionFetcherSA, deployNamespace) + err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace) if err != nil { deploy.logger.Error("error creating role binding for function", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), + zap.String("role_binding", types.PackageGetterRB), zap.String("function_name", fn.Metadata.Name), zap.String("function_namespace", fn.Metadata.Namespace)) return err } // create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps - err = fission.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fission.SecretConfigMapGetterRB, fn.Metadata.Namespace, fission.SecretConfigMapGetterCR, fission.ClusterRole, fission.FissionFetcherSA, deployNamespace) + err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.SecretConfigMapGetterRB, fn.Metadata.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace) if err != nil { deploy.logger.Error("error creating role binding for function", zap.Error(err), - zap.String("role_binding", fission.SecretConfigMapGetterRB), + zap.String("role_binding", types.SecretConfigMapGetterRB), zap.String("function_name", fn.Metadata.Name), zap.String("function_namespace", fn.Metadata.Namespace)) return err @@ -165,7 +166,7 @@ func (deploy *NewDeploy) deleteDeployment(ns string, name string) error { return nil } -func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environment, +func (deploy *NewDeploy) getDeploymentSpec(fn *fv1.Function, env *fv1.Environment, deployName string, deployLabels map[string]string) (*v1beta1.Deployment, error) { replicas := int32(fn.Spec.InvokeStrategy.ExecutionStrategy.MinScale) @@ -249,7 +250,7 @@ func (deploy *NewDeploy) getDeploymentSpec(fn *crd.Function, env *crd.Environmen // getResources overrides only the resources which are overridden at function level otherwise // default to resources specified at environment level -func (deploy *NewDeploy) getResources(env *crd.Environment, fn *crd.Function) apiv1.ResourceRequirements { +func (deploy *NewDeploy) getResources(env *fv1.Environment, fn *fv1.Function) apiv1.ResourceRequirements { resources := env.Spec.Resources if resources.Requests == nil { resources.Requests = make(map[apiv1.ResourceName]resource.Quantity) @@ -281,7 +282,7 @@ func (deploy *NewDeploy) getResources(env *crd.Environment, fn *crd.Function) ap return resources } -func (deploy *NewDeploy) createOrGetHpa(hpaName string, execStrategy *fission.ExecutionStrategy, depl *v1beta1.Deployment) (*asv1.HorizontalPodAutoscaler, error) { +func (deploy *NewDeploy) createOrGetHpa(hpaName string, execStrategy *fv1.ExecutionStrategy, depl *v1beta1.Deployment) (*asv1.HorizontalPodAutoscaler, error) { minRepl := int32(execStrategy.MinScale) if minRepl == 0 { diff --git a/executor/newdeploy/newdeploymgr.go b/pkg/executor/newdeploy/newdeploymgr.go similarity index 89% rename from executor/newdeploy/newdeploymgr.go rename to pkg/executor/newdeploy/newdeploymgr.go index a787edc9..1b64b316 100644 --- a/executor/newdeploy/newdeploymgr.go +++ b/pkg/executor/newdeploy/newdeploymgr.go @@ -25,7 +25,8 @@ import ( "time" "github.com/dchest/uniuri" - "github.com/fission/fission/throttler" + "github.com/fission/fission/pkg/throttler" + "github.com/fission/fission/pkg/utils" multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "go.uber.org/zap" @@ -34,15 +35,16 @@ import ( k8sErrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/types" + k8sTypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" - "github.com/fission/fission/executor/fscache" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/fscache" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" + "github.com/fission/fission/pkg/types" ) type ( @@ -107,7 +109,7 @@ func MakeNewDeploy( throttler: throttler.MakeThrottler(1 * time.Minute), fetcherConfig: fetcherConfig, - runtimeImagePullPolicy: fission.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")), + runtimeImagePullPolicy: utils.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")), useIstio: enableIstio, idlePodReapTime: 2 * time.Minute, @@ -136,9 +138,9 @@ func (deploy *NewDeploy) Run(ctx context.Context) { func (deploy *NewDeploy) initFuncController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(deploy.crdClient, "functions", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.Function{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ + store, controller := k8sCache.NewInformer(listWatch, &fv1.Function{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - fn := obj.(*crd.Function) + fn := obj.(*fv1.Function) _, err := deploy.createFunction(fn, true) if err != nil { deploy.logger.Error("error eager creating function", @@ -147,7 +149,7 @@ func (deploy *NewDeploy) initFuncController() (k8sCache.Store, k8sCache.Controll } }, DeleteFunc: func(obj interface{}) { - fn := obj.(*crd.Function) + fn := obj.(*fv1.Function) err := deploy.deleteFunction(fn) if err != nil { deploy.logger.Error("error deleting function", @@ -156,8 +158,8 @@ func (deploy *NewDeploy) initFuncController() (k8sCache.Store, k8sCache.Controll } }, UpdateFunc: func(oldObj interface{}, newObj interface{}) { - oldFn := oldObj.(*crd.Function) - newFn := newObj.(*crd.Function) + oldFn := oldObj.(*fv1.Function) + newFn := newObj.(*fv1.Function) err := deploy.updateFunction(oldFn, newFn) if err != nil { deploy.logger.Error("error updating function", @@ -173,12 +175,12 @@ func (deploy *NewDeploy) initFuncController() (k8sCache.Store, k8sCache.Controll func (deploy *NewDeploy) initEnvController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(deploy.crdClient, "environments", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.Environment{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ + store, controller := k8sCache.NewInformer(listWatch, &fv1.Environment{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) {}, DeleteFunc: func(obj interface{}) {}, UpdateFunc: func(oldObj interface{}, newObj interface{}) { - newEnv := newObj.(*crd.Environment) - oldEnv := oldObj.(*crd.Environment) + newEnv := newObj.(*fv1.Environment) + oldEnv := oldObj.(*fv1.Environment) // Currently only an image update in environment calls for function's deployment recreation. In future there might be more attributes which would want to do it if oldEnv.Spec.Runtime.Image != newEnv.Spec.Runtime.Image { deploy.logger.Info("Updating all function of the environment that changed, old env:", zap.Any("environment", oldEnv)) @@ -199,12 +201,12 @@ func (deploy *NewDeploy) initEnvController() (k8sCache.Store, k8sCache.Controlle return store, controller } -func (deploy *NewDeploy) getEnvFunctions(m *metav1.ObjectMeta) []crd.Function { +func (deploy *NewDeploy) getEnvFunctions(m *metav1.ObjectMeta) []fv1.Function { funcList, err := deploy.fissionClient.Functions(m.Namespace).List(metav1.ListOptions{}) if err != nil { deploy.logger.Error("Error getting functions for env", zap.Error(err), zap.Any("environment", m)) } - relatedFunctions := make([]crd.Function, 0) + relatedFunctions := make([]fv1.Function, 0) for _, f := range funcList.Items { if (f.Spec.Environment.Name == m.Name) && (f.Spec.Environment.Namespace == m.Namespace) { relatedFunctions = append(relatedFunctions, f) @@ -221,8 +223,8 @@ func (deploy *NewDeploy) GetFuncSvc(ctx context.Context, metadata *metav1.Object return deploy.createFunction(fn, false) } -func (deploy *NewDeploy) createFunction(fn *crd.Function, firstcreate bool) (*fscache.FuncSvc, error) { - if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy { +func (deploy *NewDeploy) createFunction(fn *fv1.Function, firstcreate bool) (*fscache.FuncSvc, error) { + if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy { return nil, nil } @@ -241,8 +243,8 @@ func (deploy *NewDeploy) createFunction(fn *crd.Function, firstcreate bool) (*fs return fsvc, err } -func (deploy *NewDeploy) deleteFunction(fn *crd.Function) error { - if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy { +func (deploy *NewDeploy) deleteFunction(fn *fv1.Function) error { + if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy { return nil } err := deploy.fnDelete(fn) @@ -252,7 +254,7 @@ func (deploy *NewDeploy) deleteFunction(fn *crd.Function) error { return err } -func (deploy *NewDeploy) fnCreate(fn *crd.Function, firstcreate bool) (*fscache.FuncSvc, error) { +func (deploy *NewDeploy) fnCreate(fn *fv1.Function, firstcreate bool) (*fscache.FuncSvc, error) { env, err := deploy.fissionClient. Environments(fn.Spec.Environment.Namespace). Get(fn.Spec.Environment.Name) @@ -348,21 +350,21 @@ func (deploy *NewDeploy) fnCreate(fn *crd.Function, firstcreate bool) (*fscache. return fsvc, nil } -func (deploy *NewDeploy) updateFunction(oldFn *crd.Function, newFn *crd.Function) error { +func (deploy *NewDeploy) updateFunction(oldFn *fv1.Function, newFn *fv1.Function) error { if oldFn.Metadata.ResourceVersion == newFn.Metadata.ResourceVersion { return nil } // Ignoring updates to functions which are not of NewDeployment type - if newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy && - oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy { + if newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy && + oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy { return nil } // Executor type is no longer New Deployment - if newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy && - oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy { + if newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy && + oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeNewdeploy { deploy.logger.Info("function does not use new deployment executor anymore, deleting resources", zap.Any("function", newFn)) // IMP - pass the oldFn, as the new/modified function is not in cache @@ -370,8 +372,8 @@ func (deploy *NewDeploy) updateFunction(oldFn *crd.Function, newFn *crd.Function } // Executor type changed to New Deployment from something else - if oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypeNewdeploy && - newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy { + if oldFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypeNewdeploy && + newFn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeNewdeploy { deploy.logger.Info("function type changed to new deployment, creating resources", zap.Any("old_function", oldFn.Metadata), zap.Any("new_function", newFn.Metadata)) @@ -474,7 +476,7 @@ func (deploy *NewDeploy) updateFunction(oldFn *crd.Function, newFn *crd.Function return nil } -func (deploy *NewDeploy) updateFuncDeployment(fn *crd.Function, env *crd.Environment) error { +func (deploy *NewDeploy) updateFuncDeployment(fn *fv1.Function, env *fv1.Environment) error { fsvc, err := deploy.fsCache.GetByFunctionUID(fn.Metadata.UID) if err != nil { @@ -508,7 +510,7 @@ func (deploy *NewDeploy) updateFuncDeployment(fn *crd.Function, env *crd.Environ return nil } -func (deploy *NewDeploy) fnDelete(fn *crd.Function) error { +func (deploy *NewDeploy) fnDelete(fn *fv1.Function) error { var multierr *multierror.Error // GetByFunction uses resource version as part of cache key, however, @@ -544,20 +546,20 @@ func (deploy *NewDeploy) fnDelete(fn *crd.Function) error { } // getObjName returns a unique name for kubernetes objects of function -func (deploy *NewDeploy) getObjName(fn *crd.Function) string { +func (deploy *NewDeploy) getObjName(fn *fv1.Function) string { return strings.ToLower(fmt.Sprintf("newdeploy-%v-%v-%v", fn.Metadata.Name, fn.Metadata.Namespace, uniuri.NewLen(8))) } -func (deploy *NewDeploy) getDeployLabels(fn *crd.Function, env *crd.Environment) map[string]string { +func (deploy *NewDeploy) getDeployLabels(fn *fv1.Function, env *fv1.Environment) map[string]string { return map[string]string{ - fission.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID, - fission.EXECUTOR_TYPE: fission.ExecutorTypeNewdeploy, - fission.ENVIRONMENT_NAME: env.Metadata.Name, - fission.ENVIRONMENT_NAMESPACE: env.Metadata.Namespace, - fission.ENVIRONMENT_UID: string(env.Metadata.UID), - fission.FUNCTION_NAME: fn.Metadata.Name, - fission.FUNCTION_NAMESPACE: fn.Metadata.Namespace, - fission.FUNCTION_UID: string(fn.Metadata.UID), + types.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID, + types.EXECUTOR_TYPE: fv1.ExecutorTypeNewdeploy, + types.ENVIRONMENT_NAME: env.Metadata.Name, + types.ENVIRONMENT_NAMESPACE: env.Metadata.Namespace, + types.ENVIRONMENT_UID: string(env.Metadata.UID), + types.FUNCTION_NAME: fn.Metadata.Name, + types.FUNCTION_NAMESPACE: fn.Metadata.Namespace, + types.FUNCTION_UID: string(fn.Metadata.UID), } } @@ -577,7 +579,7 @@ func (deploy *NewDeploy) updateKubeObjRefRV(fsvc *fscache.FuncSvc, objKind strin // updateStatus is a function which updates status of update. // Current implementation only logs messages, in future it will update function status -func (deploy *NewDeploy) updateStatus(fn *crd.Function, err error, message string) { +func (deploy *NewDeploy) updateStatus(fn *fv1.Function, err error, message string) { deploy.logger.Info("function status update", zap.Error(err), zap.Any("function", fn), zap.String("message", message)) } @@ -629,7 +631,7 @@ func (deploy *NewDeploy) idleObjectReaper() { deploy.logger.Fatal("failed to get environment list", zap.Error(err)) } - envList := make(map[types.UID]struct{}) + envList := make(map[k8sTypes.UID]struct{}) for _, env := range envs.Items { envList[env.Metadata.UID] = struct{}{} } diff --git a/executor/poolmgr/funcwatcher.go b/pkg/executor/poolmgr/funcwatcher.go similarity index 82% rename from executor/poolmgr/funcwatcher.go rename to pkg/executor/poolmgr/funcwatcher.go index 34700cc5..a90bae27 100644 --- a/executor/poolmgr/funcwatcher.go +++ b/pkg/executor/poolmgr/funcwatcher.go @@ -19,6 +19,7 @@ package poolmgr import ( "time" + "github.com/fission/fission/pkg/types" "go.uber.org/zap" apiv1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -28,8 +29,9 @@ import ( "k8s.io/client-go/kubernetes" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/utils" ) func getIstioServiceLabels(fnName string) map[string]string { @@ -44,10 +46,10 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie resyncPeriod := 30 * time.Second lw := k8sCache.NewListWatchFromClient(fissionClient.GetCrdClient(), "functions", metav1.NamespaceAll, fields.Everything()) - funcStore, controller := k8sCache.NewInformer(lw, &crd.Function{}, resyncPeriod, + funcStore, controller := k8sCache.NewInformer(lw, &fv1.Function{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - fn := obj.(*crd.Function) + fn := obj.(*fv1.Function) // Since istio only allows accessing pod through k8s service, // for the functions with executor type "poolmgr" we need to @@ -58,7 +60,7 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie // In some cases, user may not enter the executorType explicitly, for example in his spec.yaml. // we assume it to be of type poolmgr - if fnExecutorType != "" && fnExecutorType != fission.ExecutorTypePoolmgr { + if fnExecutorType != "" && fnExecutorType != fv1.ExecutorTypePoolmgr { return } @@ -72,12 +74,12 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie // setup rolebinding is tried, if it fails, we dont return. we just log an error and move on, because : // 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case. // 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor. - err := fission.SetupRoleBinding(gpm.logger, kubernetesClient, fission.SecretConfigMapGetterRB, fn.Metadata.Namespace, fission.SecretConfigMapGetterCR, fission.ClusterRole, fission.FissionFetcherSA, envNs) + err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB, fn.Metadata.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs) if err != nil { - gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fission.SecretConfigMapGetterRB)) + gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB)) } else { gpm.logger.Info("successfully set up rolebinding for fetcher service account for function", - zap.String("service_account", fission.FissionFetcherSA), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namepsace", envNs), zap.String("function_name", fn.Metadata.Name), zap.String("function_namespace", fn.Metadata.Namespace)) @@ -91,7 +93,7 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie "functionUid": string(fn.Metadata.UID), } - svcName := fission.GetFunctionIstioServiceName(fn.Metadata.Name, fn.Metadata.Namespace) + svcName := utils.GetFunctionIstioServiceName(fn.Metadata.Name, fn.Metadata.Namespace) // service for accepting user traffic svc := apiv1.Service{ @@ -140,10 +142,10 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie }, DeleteFunc: func(obj interface{}) { - fn := obj.(*crd.Function) + fn := obj.(*fv1.Function) fnExecutorType := fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType - if fnExecutorType != "" && fnExecutorType != fission.ExecutorTypePoolmgr { + if fnExecutorType != "" && fnExecutorType != fv1.ExecutorTypePoolmgr { return } @@ -153,7 +155,7 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie } if istioEnabled { - svcName := fission.GetFunctionIstioServiceName(fn.Metadata.Name, fn.Metadata.Namespace) + svcName := utils.GetFunctionIstioServiceName(fn.Metadata.Name, fn.Metadata.Namespace) // delete function istio service err := kubernetesClient.CoreV1().Services(envNs).Delete(svcName, nil) if err != nil && !kerrors.IsNotFound(err) { @@ -167,8 +169,8 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie }, UpdateFunc: func(oldObj, newObj interface{}) { - oldFunc := oldObj.(*crd.Function) - newFunc := newObj.(*crd.Function) + oldFunc := oldObj.(*fv1.Function) + newFunc := newObj.(*fv1.Function) if oldFunc.Metadata.ResourceVersion == newFunc.Metadata.ResourceVersion { return @@ -176,8 +178,8 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie envChanged := (oldFunc.Spec.Environment.Namespace != newFunc.Spec.Environment.Namespace) - executorTypeChangedToPM := (oldFunc.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fission.ExecutorTypePoolmgr && - newFunc.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypePoolmgr) + executorTypeChangedToPM := (oldFunc.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType != fv1.ExecutorTypePoolmgr && + newFunc.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypePoolmgr) // if a func's env reference gets updated and the newly referenced env is in a different ns, // we need to create a rolebinding in func's ns so that the fetcher-sa in env ns has access @@ -190,15 +192,15 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie envNs = newFunc.Spec.Environment.Namespace } - err := fission.SetupRoleBinding(gpm.logger, kubernetesClient, fission.SecretConfigMapGetterRB, - newFunc.Metadata.Namespace, fission.SecretConfigMapGetterCR, fission.ClusterRole, - fission.FissionFetcherSA, envNs) + err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB, + newFunc.Metadata.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, + types.FissionFetcherSA, envNs) if err != nil { - gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fission.SecretConfigMapGetterRB)) + gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB)) } else { gpm.logger.Info("successfully set up rolebinding for fetcher service account for function", - zap.String("service_account", fission.FissionFetcherSA), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namepsace", envNs), zap.String("function_name", newFunc.Metadata.Name), zap.String("function_namespace", newFunc.Metadata.Namespace)) diff --git a/executor/poolmgr/gp.go b/pkg/executor/poolmgr/gp.go similarity index 92% rename from executor/poolmgr/gp.go rename to pkg/executor/poolmgr/gp.go index 5ca168d4..92c8d96e 100644 --- a/executor/poolmgr/gp.go +++ b/pkg/executor/poolmgr/gp.go @@ -26,6 +26,8 @@ import ( "time" "github.com/dchest/uniuri" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" multierror "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "go.uber.org/zap" @@ -36,18 +38,18 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - fetcherClient "github.com/fission/fission/environments/fetcher/client" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" - "github.com/fission/fission/executor/fscache" - "github.com/fission/fission/executor/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/fscache" + "github.com/fission/fission/pkg/executor/util" + fetcherClient "github.com/fission/fission/pkg/fetcher/client" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" ) type ( GenericPool struct { logger *zap.Logger - env *crd.Environment + env *fv1.Environment replicas int32 // num idle pods deployment *v1beta1.Deployment // kubernetes deployment namespace string // namespace to keep our resources @@ -82,7 +84,7 @@ func MakeGenericPool( logger *zap.Logger, fissionClient *crd.FissionClient, kubernetesClient *kubernetes.Clientset, - env *crd.Environment, + env *fv1.Environment, initialReplicas int32, namespace string, functionNamespace string, @@ -116,7 +118,7 @@ func MakeGenericPool( useIstio: enableIstio, // defaults off -- istio integration requires pod relabeling and it takes a second or more to become routable, slowing cold start } - gp.runtimeImagePullPolicy = fission.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")) + gp.runtimeImagePullPolicy = utils.GetImagePullPolicy(os.Getenv("RUNTIME_IMAGE_PULL_POLICY")) // create fetcher SA in this ns, if not already created err := fetcherConfig.SetupServiceAccount(gp.kubernetesClient, gp.namespace, nil) @@ -141,12 +143,12 @@ func MakeGenericPool( func (gp *GenericPool) getDeployLabels() map[string]string { return map[string]string{ - fission.EXECUTOR_INSTANCEID_LABEL: gp.instanceId, - fission.EXECUTOR_TYPE: fission.ExecutorTypePoolmgr, - fission.ENVIRONMENT_NAME: gp.env.Metadata.Name, - fission.ENVIRONMENT_NAMESPACE: gp.env.Metadata.Namespace, - fission.ENVIRONMENT_UID: string(gp.env.Metadata.UID), - "managed": "true", // this allows us to easily find pods managed by the deployment + fv1.EXECUTOR_INSTANCEID_LABEL: gp.instanceId, + types.EXECUTOR_TYPE: fv1.ExecutorTypePoolmgr, + types.ENVIRONMENT_NAME: gp.env.Metadata.Name, + types.ENVIRONMENT_NAMESPACE: gp.env.Metadata.Namespace, + types.ENVIRONMENT_UID: string(gp.env.Metadata.UID), + "managed": "true", // this allows us to easily find pods managed by the deployment } } @@ -201,7 +203,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro pod := podList.Items[i] // Ignore not ready pod here - if !fission.IsReadyPod(&pod) { + if !utils.IsReadyPod(&pod) { continue } @@ -227,7 +229,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro // and make a good scheduling decision. chosenPod := readyPods[rand.Intn(len(readyPods))] - if gp.env.Spec.AllowedFunctionsPerContainer != fission.AllowedFunctionsPerContainerInfinite { + if gp.env.Spec.AllowedFunctionsPerContainer != types.AllowedFunctionsPerContainerInfinite { // Relabel. If the pod already got picked and // modified, this should fail; in that case just // retry. @@ -246,10 +248,10 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro func (gp *GenericPool) labelsForFunction(metadata *metav1.ObjectMeta) map[string]string { label := gp.getDeployLabels() - label[fission.FUNCTION_NAME] = metadata.Name - label[fission.FUNCTION_UID] = string(metadata.UID) - label[fission.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD - label["managed"] = "false" // this allows us to easily find pods not managed by the deployment + label[types.FUNCTION_NAME] = metadata.Name + label[types.FUNCTION_UID] = string(metadata.UID) + label[types.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD + label["managed"] = "false" // this allows us to easily find pods not managed by the deployment return label } @@ -305,7 +307,7 @@ func (gp *GenericPool) specializePod(ctx context.Context, pod *apiv1.Pod, metada } // specialize pod with service if gp.useIstio { - svc := fission.GetFunctionIstioServiceName(metadata.Name, metadata.Namespace) + svc := utils.GetFunctionIstioServiceName(metadata.Name, metadata.Namespace) podIP = fmt.Sprintf("%v.%v", svc, gp.namespace) } @@ -569,7 +571,7 @@ func (gp *GenericPool) GetFuncSvc(ctx context.Context, m *metav1.ObjectMeta) (*f // namespace-qualified hostname svcHost = fmt.Sprintf("%v.%v", svcName, gp.namespace) } else if gp.useIstio { - svc := fission.GetFunctionIstioServiceName(m.Name, m.Namespace) + svc := utils.GetFunctionIstioServiceName(m.Name, m.Namespace) svcHost = fmt.Sprintf("%v.%v:8888", svc, gp.namespace) } else { gp.logger.Info("using pod IP for specialized pod", zap.String("pod", pod.ObjectMeta.Name), zap.String("function", m.Name)) diff --git a/executor/poolmgr/gpm.go b/pkg/executor/poolmgr/gpm.go similarity index 89% rename from executor/poolmgr/gpm.go rename to pkg/executor/poolmgr/gpm.go index be845def..34e89b6c 100644 --- a/executor/poolmgr/gpm.go +++ b/pkg/executor/poolmgr/gpm.go @@ -23,18 +23,20 @@ import ( "strings" "time" + "github.com/fission/fission/pkg/utils" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" + k8sTypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" - fetcherConfig "github.com/fission/fission/environments/fetcher/config" - "github.com/fission/fission/executor/fscache" - "github.com/fission/fission/executor/reaper" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/executor/fscache" + "github.com/fission/fission/pkg/executor/reaper" + fetcherConfig "github.com/fission/fission/pkg/fetcher/config" + "github.com/fission/fission/pkg/types" ) type requestType int @@ -70,8 +72,8 @@ type ( } request struct { requestType - env *crd.Environment - envList []crd.Environment + env *fv1.Environment + envList []fv1.Environment responseChannel chan *response } response struct { @@ -139,7 +141,7 @@ func (gpm *GenericPoolManager) service() { if !ok { poolsize := gpm.getEnvPoolsize(req.env) switch req.env.Spec.AllowedFunctionsPerContainer { - case fission.AllowedFunctionsPerContainerInfinite: + case types.AllowedFunctionsPerContainerInfinite: poolsize = 1 } @@ -170,7 +172,7 @@ func (gpm *GenericPoolManager) service() { if !ok || poolsize == 0 { // Env no longer exists or pool size changed to zero - gpm.logger.Info("eestroying generic pool", zap.Any("environment", pool.env.Metadata)) + gpm.logger.Info("destroying generic pool", zap.Any("environment", pool.env.Metadata)) delete(gpm.pools, key) // and delete the pool asynchronously. @@ -182,7 +184,7 @@ func (gpm *GenericPoolManager) service() { } } -func (gpm *GenericPoolManager) GetPool(env *crd.Environment) (*GenericPool, error) { +func (gpm *GenericPoolManager) GetPool(env *fv1.Environment) (*GenericPool, error) { c := make(chan *response) gpm.requestChannel <- &request{ requestType: GET_POOL, @@ -193,7 +195,7 @@ func (gpm *GenericPoolManager) GetPool(env *crd.Environment) (*GenericPool, erro return resp.pool, resp.error } -func (gpm *GenericPoolManager) CleanupPools(envs []crd.Environment) { +func (gpm *GenericPoolManager) CleanupPools(envs []fv1.Environment) { gpm.requestChannel <- &request{ requestType: CLEANUP_POOLS, envList: envs, @@ -218,13 +220,13 @@ func (gpm *GenericPoolManager) GetFuncSvc(ctx context.Context, metadata *metav1. return pool.GetFuncSvc(ctx, metadata) } -func (gpm *GenericPoolManager) getFunctionEnv(m *metav1.ObjectMeta) (*crd.Environment, error) { - var env *crd.Environment +func (gpm *GenericPoolManager) getFunctionEnv(m *metav1.ObjectMeta) (*fv1.Environment, error) { + var env *fv1.Environment // Cached ? result, err := gpm.functionEnv.Get(crd.CacheKey(m)) if err == nil { - env = result.(*crd.Environment) + env = result.(*fv1.Environment) return env, nil } @@ -253,7 +255,7 @@ func (gpm *GenericPoolManager) eagerPoolCreator() { // get list of envs from controller envs, err := gpm.fissionClient.Environments(metav1.NamespaceAll).List(metav1.ListOptions{}) if err != nil { - if fission.IsNetworkError(err) { + if utils.IsNetworkError(err) { gpm.logger.Error("encountered network error, retrying", zap.Error(err)) time.Sleep(5 * time.Second) continue @@ -282,7 +284,7 @@ func (gpm *GenericPoolManager) eagerPoolCreator() { } } -func (gpm *GenericPoolManager) getEnvPoolsize(env *crd.Environment) int32 { +func (gpm *GenericPoolManager) getEnvPoolsize(env *fv1.Environment) int32 { var poolsize int32 if env.Spec.Version < 3 { poolsize = 3 @@ -298,7 +300,7 @@ func (gpm *GenericPoolManager) IsValid(fsvc *fscache.FuncSvc) bool { for _, obj := range fsvc.KubernetesObjects { if obj.Kind == "pod" { pod, err := gpm.kubernetesClient.CoreV1().Pods(obj.Namespace).Get(obj.Name, metav1.GetOptions{}) - if err == nil && strings.Contains(fsvc.Address, pod.Status.PodIP) && fission.IsReadyPod(pod) { + if err == nil && strings.Contains(fsvc.Address, pod.Status.PodIP) && utils.IsReadyPod(pod) { gpm.logger.Info("valid pod address", zap.String("address", fsvc.Address)) return true } @@ -319,7 +321,7 @@ func (gpm *GenericPoolManager) idleObjectReaper() { gpm.logger.Fatal("failed to get environment list", zap.Error(err)) } - envList := make(map[types.UID]struct{}) + envList := make(map[k8sTypes.UID]struct{}) for _, env := range envs.Items { envList[env.Metadata.UID] = struct{}{} } @@ -343,7 +345,7 @@ func (gpm *GenericPoolManager) idleObjectReaper() { zap.String("function", fsvc.Name)) } - if fsvc.Environment.Spec.AllowedFunctionsPerContainer == fission.AllowedFunctionsPerContainerInfinite { + if fsvc.Environment.Spec.AllowedFunctionsPerContainer == types.AllowedFunctionsPerContainerInfinite { continue } diff --git a/executor/poolmgr/packagewatcher.go b/pkg/executor/poolmgr/packagewatcher.go similarity index 79% rename from executor/poolmgr/packagewatcher.go rename to pkg/executor/poolmgr/packagewatcher.go index 02a9ae0b..6559a82f 100644 --- a/executor/poolmgr/packagewatcher.go +++ b/pkg/executor/poolmgr/packagewatcher.go @@ -19,14 +19,16 @@ package poolmgr import ( "time" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/client-go/kubernetes" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" ) // TODO : It may make sense to make each of add, update, delete funcs run as separate go routines. @@ -35,10 +37,10 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien resyncPeriod := 30 * time.Second lw := k8sCache.NewListWatchFromClient(fissionClient.GetCrdClient(), "packages", metav1.NamespaceAll, fields.Everything()) - pkgStore, controller := k8sCache.NewInformer(lw, &crd.Package{}, resyncPeriod, + pkgStore, controller := k8sCache.NewInformer(lw, &fv1.Package{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - pkg := obj.(*crd.Package) + pkg := obj.(*fv1.Package) gpm.logger.Debug("list watch for package reported a new package addition", zap.String("package_name", pkg.Metadata.Name), zap.String("package_namepsace", pkg.Metadata.Namespace)) @@ -51,26 +53,26 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien // here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for // every function's package to be loaded into its env. without that, there's no point to move forward. - err := fission.SetupRoleBinding(gpm.logger, kubernetesClient, fission.PackageGetterRB, pkg.Metadata.Namespace, fission.PackageGetterCR, fission.ClusterRole, fission.FissionFetcherSA, envNs) + err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB, pkg.Metadata.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs) if err != nil { gpm.logger.Error("error creating rolebinding for package", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), + zap.String("role_binding", types.PackageGetterRB), zap.String("package_name", pkg.Metadata.Name), zap.String("package_namespace", pkg.Metadata.Namespace)) return } gpm.logger.Debug("successfully set up rolebinding for fetcher service account", - zap.String("service_account", fission.FissionFetcherSA), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namespace", envNs), zap.String("package_name", pkg.Metadata.Name), zap.String("package_namespace", pkg.Metadata.Namespace)) }, UpdateFunc: func(oldObj, newObj interface{}) { - oldPkg := oldObj.(*crd.Package) - newPkg := newObj.(*crd.Package) + oldPkg := oldObj.(*fv1.Package) + newPkg := newObj.(*fv1.Package) if oldPkg.Metadata.ResourceVersion == newPkg.Metadata.ResourceVersion { return @@ -85,20 +87,20 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien envNs = newPkg.Spec.Environment.Namespace } - err := fission.SetupRoleBinding(gpm.logger, kubernetesClient, fission.PackageGetterRB, - newPkg.Metadata.Namespace, fission.PackageGetterCR, fission.ClusterRole, - fission.FissionFetcherSA, envNs) + err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB, + newPkg.Metadata.Namespace, types.PackageGetterCR, types.ClusterRole, + types.FissionFetcherSA, envNs) if err != nil { gpm.logger.Error("error updating rolebinding for package", zap.Error(err), - zap.String("role_binding", fission.PackageGetterRB), + zap.String("role_binding", types.PackageGetterRB), zap.String("package_name", newPkg.Metadata.Name), zap.String("package_namespace", newPkg.Metadata.Namespace)) return } gpm.logger.Debug("successfully updated rolebinding for fetcher service account", - zap.String("service_account", fission.FissionFetcherSA), + zap.String("service_account", types.FissionFetcherSA), zap.String("service_account_namespace", envNs), zap.String("package_name", newPkg.Metadata.Name), zap.String("package_namespace", newPkg.Metadata.Namespace)) diff --git a/executor/reaper/reaper.go b/pkg/executor/reaper/reaper.go similarity index 91% rename from executor/reaper/reaper.go rename to pkg/executor/reaper/reaper.go index 44316e80..cae8560c 100644 --- a/executor/reaper/reaper.go +++ b/pkg/executor/reaper/reaper.go @@ -20,13 +20,14 @@ import ( "strings" "time" + "github.com/fission/fission/pkg/utils" "go.uber.org/zap" apiv1 "k8s.io/api/core/v1" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/types" ) var ( @@ -119,7 +120,7 @@ func cleanupDeployments(logger *zap.Logger, client *kubernetes.Clientset, instan return err } for _, dep := range deploymentList.Items { - id, ok := dep.ObjectMeta.Labels[fission.EXECUTOR_INSTANCEID_LABEL] + id, ok := dep.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] if ok && id != instanceId { logger.Info("cleaning up deployment", zap.String("deployment", dep.ObjectMeta.Name)) err := client.ExtensionsV1beta1().Deployments(dep.ObjectMeta.Namespace).Delete(dep.ObjectMeta.Name, &delOpt) @@ -132,7 +133,7 @@ func cleanupDeployments(logger *zap.Logger, client *kubernetes.Clientset, instan // ignore err } // Backward compatibility with older label name - pid, pok := dep.ObjectMeta.Labels[fission.POOLMGR_INSTANCEID_LABEL] + pid, pok := dep.ObjectMeta.Labels[types.POOLMGR_INSTANCEID_LABEL] if pok && pid != instanceId { logger.Info("cleaning up deployment", zap.String("deployment", dep.ObjectMeta.Name)) err := client.ExtensionsV1beta1().Deployments(dep.ObjectMeta.Namespace).Delete(dep.ObjectMeta.Name, &delOpt) @@ -154,7 +155,7 @@ func cleanupPods(logger *zap.Logger, client *kubernetes.Clientset, instanceId st return err } for _, pod := range podList.Items { - id, ok := pod.ObjectMeta.Labels[fission.EXECUTOR_INSTANCEID_LABEL] + id, ok := pod.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] if ok && id != instanceId { logger.Info("cleaning up pod", zap.String("pod", pod.ObjectMeta.Name)) err := client.CoreV1().Pods(pod.ObjectMeta.Namespace).Delete(pod.ObjectMeta.Name, nil) @@ -167,7 +168,7 @@ func cleanupPods(logger *zap.Logger, client *kubernetes.Clientset, instanceId st // ignore err } // Backward compatibility with older label name - pid, pok := pod.ObjectMeta.Labels[fission.POOLMGR_INSTANCEID_LABEL] + pid, pok := pod.ObjectMeta.Labels[types.POOLMGR_INSTANCEID_LABEL] if pok && pid != instanceId { logger.Info("cleaning up pod", zap.String("pod", pod.ObjectMeta.Name)) err := client.CoreV1().Pods(pod.ObjectMeta.Namespace).Delete(pod.ObjectMeta.Name, nil) @@ -190,7 +191,7 @@ func cleanupServices(logger *zap.Logger, client *kubernetes.Clientset, instanceI return err } for _, svc := range svcList.Items { - id, ok := svc.ObjectMeta.Labels[fission.EXECUTOR_INSTANCEID_LABEL] + id, ok := svc.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] if ok && id != instanceId { logger.Info("cleaning up service", zap.String("service", svc.ObjectMeta.Name)) err := client.CoreV1().Services(svc.ObjectMeta.Namespace).Delete(svc.ObjectMeta.Name, nil) @@ -213,7 +214,7 @@ func cleanupHpa(logger *zap.Logger, client *kubernetes.Clientset, instanceId str } for _, hpa := range hpaList.Items { - id, ok := hpa.ObjectMeta.Labels[fission.EXECUTOR_INSTANCEID_LABEL] + id, ok := hpa.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL] if ok && id != instanceId { logger.Info("cleaning up HPA", zap.String("hpa", hpa.ObjectMeta.Name)) err := client.AutoscalingV1().HorizontalPodAutoscalers(hpa.ObjectMeta.Namespace).Delete(hpa.ObjectMeta.Name, nil) @@ -252,7 +253,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi } // ignore role-bindings not created by fission - if roleBinding.Name != fission.PackageGetterRB && roleBinding.Name != fission.SecretConfigMapGetterRB { + if roleBinding.Name != types.PackageGetterRB && roleBinding.Name != types.SecretConfigMapGetterRB { continue } @@ -295,7 +296,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi break } - if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy { + if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == types.ExecutorTypeNewdeploy { ndmFunc = true break } @@ -303,7 +304,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi // if its a package-getterr-rb, we have 2 kinds of SAs and each of them is handled differently // else if its a secret-configmap-rb, we have only one SA which is fission-fetcher - if roleBinding.Name == fission.PackageGetterRB { + if roleBinding.Name == types.PackageGetterRB { // check if there is an env obj in saNs envList, err := fissionClient.Environments(saNs).List(meta_v1.ListOptions{}) if err != nil { @@ -316,9 +317,9 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi // if there's at least one function in the role-binding namespace with env reference // to the SA's namespace. // if neither, then we can remove this SA from this role-binding - if subj.Name == fission.FissionBuilderSA { + if subj.Name == types.FissionBuilderSA { if len(envList.Items) == 0 && !funcEnvReference { - saToRemove[fission.MakeSAMapKey(subj.Name, subj.Namespace)] = true + saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true } } @@ -326,18 +327,18 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi // we also need to check if there's at least one function with executor type New deploy // in the rolebinding's namespace. // if none of them are true, then remove this SA from this role-binding - if subj.Name == fission.FissionFetcherSA { + if subj.Name == types.FissionFetcherSA { if len(envList.Items) == 0 && !ndmFunc && !funcEnvReference { // remove SA from rolebinding - saToRemove[fission.MakeSAMapKey(subj.Name, subj.Namespace)] = true + saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true } } - } else if roleBinding.Name == fission.SecretConfigMapGetterRB { + } else if roleBinding.Name == types.SecretConfigMapGetterRB { // if there's not even one function in the role-binding's namespace and there's not even // one function with env reference to the SA's namespace, then remove that SA // from this role-binding if !ndmFunc && !funcEnvReference { - saToRemove[fission.MakeSAMapKey(subj.Name, subj.Namespace)] = true + saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true } } } @@ -351,7 +352,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi zap.String("role_binding_namespace", roleBinding.Namespace)) // call this once in the end for each role-binding - err = fission.RemoveSAFromRoleBindingWithRetries(logger, client, roleBinding.Name, roleBinding.Namespace, saToRemove) + err = utils.RemoveSAFromRoleBindingWithRetries(logger, client, roleBinding.Name, roleBinding.Namespace, saToRemove) if err != nil { // if there's an error, we just log it and proceed with the next role-binding, hoping that this role-binding // will be processed in next iteration. diff --git a/executor/util/merge.go b/pkg/executor/util/merge.go similarity index 100% rename from executor/util/merge.go rename to pkg/executor/util/merge.go diff --git a/executor/util/merge_test.go b/pkg/executor/util/merge_test.go similarity index 100% rename from executor/util/merge_test.go rename to pkg/executor/util/merge_test.go diff --git a/featureconfig/config.go b/pkg/featureconfig/config.go similarity index 100% rename from featureconfig/config.go rename to pkg/featureconfig/config.go diff --git a/featureconfig/types.go b/pkg/featureconfig/types.go similarity index 100% rename from featureconfig/types.go rename to pkg/featureconfig/types.go diff --git a/environments/fetcher/client/client.go b/pkg/fetcher/client/client.go similarity index 80% rename from environments/fetcher/client/client.go rename to pkg/fetcher/client/client.go index bd591323..81fba94a 100644 --- a/environments/fetcher/client/client.go +++ b/pkg/fetcher/client/client.go @@ -15,7 +15,8 @@ import ( "go.opencensus.io/plugin/ochttp" "golang.org/x/net/context/ctxhttp" - "github.com/fission/fission" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/types" ) type ( @@ -48,20 +49,20 @@ func (c *Client) getUploadUrl() string { return c.url + "/upload" } -func (c *Client) Specialize(ctx context.Context, req *fission.FunctionSpecializeRequest) error { +func (c *Client) Specialize(ctx context.Context, req *types.FunctionSpecializeRequest) error { _, err := sendRequest(c.logger, ctx, c.httpClient, req, c.getSpecializeUrl()) return err } -func (c *Client) Fetch(ctx context.Context, fr *fission.FunctionFetchRequest) error { +func (c *Client) Fetch(ctx context.Context, fr *types.FunctionFetchRequest) error { _, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getFetchUrl()) return err } -func (c *Client) Upload(ctx context.Context, fr *fission.ArchiveUploadRequest) (*fission.ArchiveUploadResponse, error) { +func (c *Client) Upload(ctx context.Context, fr *types.ArchiveUploadRequest) (*types.ArchiveUploadResponse, error) { body, err := sendRequest(c.logger, ctx, c.httpClient, fr, c.getUploadUrl()) - uploadResp := fission.ArchiveUploadResponse{} + uploadResp := types.ArchiveUploadResponse{} err = json.Unmarshal(body, &uploadResp) if err != nil { return nil, err @@ -91,7 +92,7 @@ func sendRequest(logger *zap.Logger, ctx context.Context, httpClient *http.Clien resp.Body.Close() return body, err } - err = fission.MakeErrorFromHTTP(resp) + err = ferror.MakeErrorFromHTTP(resp) } if i < maxRetries-1 { diff --git a/environments/fetcher/config/config.go b/pkg/fetcher/config/config.go similarity index 88% rename from environments/fetcher/config/config.go rename to pkg/fetcher/config/config.go index cd179186..cbb073c6 100644 --- a/environments/fetcher/config/config.go +++ b/pkg/fetcher/config/config.go @@ -7,14 +7,15 @@ import ( "os" "path/filepath" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - crd "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type Config struct { @@ -90,19 +91,19 @@ func MakeFetcherConfig(sharedMountPath string) (*Config, error) { return &Config{ resourceRequirements: resources, fetcherImage: fetcherImage, - fetcherImagePullPolicy: fission.GetImagePullPolicy(fetcherImagePullPolicy), + fetcherImagePullPolicy: utils.GetImagePullPolicy(fetcherImagePullPolicy), sharedMountPath: sharedMountPath, sharedSecretPath: "/secrets", sharedCfgMapPath: "/configs", jaegerCollectorEndpoint: os.Getenv("OPENCENSUS_TRACE_JAEGER_COLLECTOR_ENDPOINT"), - serviceAccount: fission.FissionFetcherSA, + serviceAccount: types.FissionFetcherSA, }, nil } func (cfg *Config) SetupServiceAccount(kubernetesClient *kubernetes.Clientset, namespace string, context interface{}) error { - _, err := fission.SetupSA(kubernetesClient, fission.FissionFetcherSA, namespace) + _, err := utils.SetupSA(kubernetesClient, types.FissionFetcherSA, namespace) if err != nil { - log.Printf("Error : %v creating %s in ns : %s for: %#v", err, fission.FissionFetcherSA, namespace, context) + log.Printf("Error : %v creating %s in ns : %s for: %#v", err, types.FissionFetcherSA, namespace, context) return err } @@ -113,7 +114,7 @@ func (cfg *Config) SharedMountPath() string { return cfg.sharedMountPath } -func (cfg *Config) NewSpecializeRequest(fn *crd.Function, env *crd.Environment) fission.FunctionSpecializeRequest { +func (cfg *Config) NewSpecializeRequest(fn *fv1.Function, env *fv1.Environment) types.FunctionSpecializeRequest { // for backward compatibility, since most v1 env // still try to load user function from hard coded // path /userfunc/user @@ -122,9 +123,9 @@ func (cfg *Config) NewSpecializeRequest(fn *crd.Function, env *crd.Environment) targetFilename = string(fn.Metadata.UID) } - return fission.FunctionSpecializeRequest{ - FetchReq: fission.FunctionFetchRequest{ - FetchType: fission.FETCH_DEPLOYMENT, + return types.FunctionSpecializeRequest{ + FetchReq: types.FunctionFetchRequest{ + FetchType: types.FETCH_DEPLOYMENT, Package: metav1.ObjectMeta{ Namespace: fn.Spec.Package.PackageRef.Namespace, Name: fn.Spec.Package.PackageRef.Name, @@ -134,7 +135,7 @@ func (cfg *Config) NewSpecializeRequest(fn *crd.Function, env *crd.Environment) ConfigMaps: fn.Spec.ConfigMaps, KeepArchive: env.Spec.KeepArchive, }, - LoadReq: fission.FunctionLoadRequest{ + LoadReq: types.FunctionLoadRequest{ FilePath: filepath.Join(cfg.sharedMountPath, targetFilename), FunctionName: fn.Spec.Package.FunctionName, FunctionMetadata: &fn.Metadata, @@ -147,7 +148,7 @@ func (cfg *Config) AddFetcherToPodSpec(podSpec *apiv1.PodSpec, mainContainerName return cfg.addFetcherToPodSpecWithCommand(podSpec, mainContainerName, cfg.fetcherCommand()) } -func (cfg *Config) AddSpecializingFetcherToPodSpec(podSpec *apiv1.PodSpec, mainContainerName string, fn *crd.Function, env *crd.Environment) error { +func (cfg *Config) AddSpecializingFetcherToPodSpec(podSpec *apiv1.PodSpec, mainContainerName string, fn *fv1.Function, env *fv1.Environment) error { specializeReq := cfg.NewSpecializeRequest(fn, env) specializePayload, err := json.Marshal(specializeReq) if err != nil { @@ -179,19 +180,19 @@ func (cfg *Config) fetcherCommand(extraArgs ...string) []string { func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) { volumes := []apiv1.Volume{ { - Name: fission.SharedVolumeUserfunc, + Name: types.SharedVolumeUserfunc, VolumeSource: apiv1.VolumeSource{ EmptyDir: &apiv1.EmptyDirVolumeSource{}, }, }, { - Name: fission.SharedVolumeSecrets, + Name: types.SharedVolumeSecrets, VolumeSource: apiv1.VolumeSource{ EmptyDir: &apiv1.EmptyDirVolumeSource{}, }, }, { - Name: fission.SharedVolumeConfigmaps, + Name: types.SharedVolumeConfigmaps, VolumeSource: apiv1.VolumeSource{ EmptyDir: &apiv1.EmptyDirVolumeSource{}, }, @@ -199,15 +200,15 @@ func (cfg *Config) volumesWithMounts() ([]apiv1.Volume, []apiv1.VolumeMount) { } mounts := []apiv1.VolumeMount{ { - Name: fission.SharedVolumeUserfunc, + Name: types.SharedVolumeUserfunc, MountPath: cfg.sharedMountPath, }, { - Name: fission.SharedVolumeSecrets, + Name: types.SharedVolumeSecrets, MountPath: cfg.sharedSecretPath, }, { - Name: fission.SharedVolumeConfigmaps, + Name: types.SharedVolumeConfigmaps, MountPath: cfg.sharedCfgMapPath, }, } @@ -296,7 +297,7 @@ func (cfg *Config) addFetcherToPodSpecWithCommand(podSpec *apiv1.PodSpec, mainCo podSpec.Volumes = append(podSpec.Volumes, volumes...) podSpec.Containers = append(podSpec.Containers, c) if podSpec.ServiceAccountName == "" { - podSpec.ServiceAccountName = fission.FissionFetcherSA + podSpec.ServiceAccountName = types.FissionFetcherSA } return nil diff --git a/environments/fetcher/fetcher.go b/pkg/fetcher/fetcher.go similarity index 92% rename from environments/fetcher/fetcher.go rename to pkg/fetcher/fetcher.go index 4bf5b901..ee355237 100644 --- a/environments/fetcher/fetcher.go +++ b/pkg/fetcher/fetcher.go @@ -26,9 +26,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - storageSvcClient "github.com/fission/fission/storagesvc/client" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/info" + storageSvcClient "github.com/fission/fission/pkg/storagesvc/client" + "github.com/fission/fission/pkg/types" ) type ( @@ -111,7 +114,7 @@ func downloadUrl(ctx context.Context, httpClient *http.Client, url string, local return nil } -func getChecksum(path string) (*fission.Checksum, error) { +func getChecksum(path string) (*fv1.Checksum, error) { f, err := os.Open(path) if err != nil { return nil, err @@ -126,18 +129,18 @@ func getChecksum(path string) (*fission.Checksum, error) { c := hex.EncodeToString(hasher.Sum(nil)) - return &fission.Checksum{ - Type: fission.ChecksumTypeSHA256, + return &fv1.Checksum{ + Type: fv1.ChecksumTypeSHA256, Sum: c, }, nil } -func verifyChecksum(fileChecksum, checksum *fission.Checksum) error { - if checksum.Type != fission.ChecksumTypeSHA256 { - return fission.MakeError(fission.ErrorInvalidArgument, "Unsupported checksum type") +func verifyChecksum(fileChecksum, checksum *fv1.Checksum) error { + if checksum.Type != fv1.ChecksumTypeSHA256 { + return ferror.MakeError(ferror.ErrorInvalidArgument, "Unsupported checksum type") } if fileChecksum.Sum != checksum.Sum { - return fission.MakeError(fission.ErrorChecksumFail, "Checksum validation failed") + return ferror.MakeError(ferror.ErrorChecksumFail, "Checksum validation failed") } return nil } @@ -155,7 +158,7 @@ func writeSecretOrConfigMap(dataMap map[string][]byte, dirPath string) error { func (fetcher *Fetcher) VersionHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") - fmt.Fprintf(w, fission.BuildInfo().String()) + fmt.Fprintf(w, info.BuildInfo().String()) } func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) { @@ -177,7 +180,7 @@ func (fetcher *Fetcher) FetchHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - var req fission.FunctionFetchRequest + var req types.FunctionFetchRequest err = json.Unmarshal(body, &req) if err != nil { fetcher.logger.Error("error parsing request body", zap.Error(err)) @@ -218,7 +221,7 @@ func (fetcher *Fetcher) SpecializeHandler(w http.ResponseWriter, r *http.Request http.Error(w, err.Error(), http.StatusInternalServerError) return } - var req fission.FunctionSpecializeRequest + var req types.FunctionSpecializeRequest err = json.Unmarshal(body, &req) if err != nil { fetcher.logger.Error("error parsing request body", zap.Error(err)) @@ -239,7 +242,7 @@ func (fetcher *Fetcher) SpecializeHandler(w http.ResponseWriter, r *http.Request // Fetch takes FetchRequest and makes the fetch call // It returns the HTTP code and error if any -func (fetcher *Fetcher) Fetch(ctx context.Context, req fission.FunctionFetchRequest) (int, error) { +func (fetcher *Fetcher) Fetch(ctx context.Context, req types.FunctionFetchRequest) (int, error) { // check that the requested filename is not an empty string and error out if so if len(req.Filename) == 0 { e := "fetch request received for an empty file name" @@ -258,7 +261,7 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, req fission.FunctionFetchRequ tmpFile := req.Filename + ".tmp" tmpPath := filepath.Join(fetcher.sharedVolumePath, tmpFile) - if req.FetchType == fission.FETCH_URL { + if req.FetchType == types.FETCH_URL { // fetch the file and save it to the tmp path err := downloadUrl(ctx, fetcher.httpClient, req.Url, tmpPath) if err != nil { @@ -277,16 +280,16 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, req fission.FunctionFetchRequ return http.StatusInternalServerError, errors.Wrap(err, e) } - var archive *fission.Archive - if req.FetchType == fission.FETCH_SOURCE { + var archive *fv1.Archive + if req.FetchType == types.FETCH_SOURCE { archive = &pkg.Spec.Source - } else if req.FetchType == fission.FETCH_DEPLOYMENT { + } else if req.FetchType == types.FETCH_DEPLOYMENT { // sometimes, the user may invoke the function even before the source code is built into a deploy pkg. // this results in executor sending a fetch request of type FETCH_DEPLOYMENT and since pkg.Spec.Deployment.Url will be empty, // we hit this "Get : unsupported protocol scheme "" error. // it may be useful to the user if we can send a more meaningful error in such a scenario. - if pkg.Status.BuildStatus != fission.BuildStatusSucceeded && pkg.Status.BuildStatus != fission.BuildStatusNone { - e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", fission.BuildStatusSucceeded) + if pkg.Status.BuildStatus != types.BuildStatusSucceeded && pkg.Status.BuildStatus != types.BuildStatusNone { + e := fmt.Sprintf("cannot fetch deployment: package build status was not %q", types.BuildStatusSucceeded) fetcher.logger.Error(e, zap.String("package_name", pkg.Metadata.Name), zap.String("package_namespace", pkg.Metadata.Namespace), @@ -361,7 +364,7 @@ func (fetcher *Fetcher) Fetch(ctx context.Context, req fission.FunctionFetchRequ // FetchSecretsAndCfgMaps fetches secrets and configmaps specified by user // It returns the HTTP code and error if any -func (fetcher *Fetcher) FetchSecretsAndCfgMaps(secrets []fission.SecretReference, cfgmaps []fission.ConfigMapReference) (int, error) { +func (fetcher *Fetcher) FetchSecretsAndCfgMaps(secrets []fv1.SecretReference, cfgmaps []fv1.ConfigMapReference) (int, error) { if len(secrets) > 0 { for _, secret := range secrets { data, err := fetcher.kubeClient.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{}) @@ -477,7 +480,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) { return } - var req fission.ArchiveUploadRequest + var req types.ArchiveUploadRequest err = json.Unmarshal(body, &req) if err != nil { fetcher.logger.Error("error parsing request body", zap.Error(err)) @@ -527,7 +530,7 @@ func (fetcher *Fetcher) UploadHandler(w http.ResponseWriter, r *http.Request) { return } - resp := fission.ArchiveUploadResponse{ + resp := types.ArchiveUploadResponse{ ArchiveDownloadUrl: ssClient.GetUrl(fileID), Checksum: *sum, } @@ -583,7 +586,7 @@ func (fetcher *Fetcher) unarchive(src string, dst string) error { return nil } -func (fetcher *Fetcher) SpecializePod(ctx context.Context, fetchReq fission.FunctionFetchRequest, loadReq fission.FunctionLoadRequest) error { +func (fetcher *Fetcher) SpecializePod(ctx context.Context, fetchReq types.FunctionFetchRequest, loadReq types.FunctionLoadRequest) error { startTime := time.Now() defer func() { elapsed := time.Since(startTime) @@ -646,7 +649,7 @@ func (fetcher *Fetcher) SpecializePod(ctx context.Context, fetchReq fission.Func } if err == nil { - err = fission.MakeErrorFromHTTP(resp) + err = ferror.MakeErrorFromHTTP(resp) } return errors.Wrap(err, "error specializing function pod") diff --git a/fission/buildwatch.go b/pkg/fission-cli/buildwatch.go similarity index 82% rename from fission/buildwatch.go rename to pkg/fission-cli/buildwatch.go index f653129c..51651071 100644 --- a/fission/buildwatch.go +++ b/pkg/fission-cli/buildwatch.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "context" @@ -23,10 +23,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/types" ) type ( @@ -73,17 +73,17 @@ func (w *packageBuildWatcher) watch(ctx context.Context) { // find packages that (a) are in the app spec and (b) have an interesting // build status (either succeeded or failed; not "none") keepWaiting := false - buildpkgs := make([]crd.Package, 0) + buildpkgs := make([]fv1.Package, 0) for _, pkg := range pkgs { _, ok := w.pkgMeta[mapKey(&pkg.Metadata)] if !ok { continue } - if pkg.Status.BuildStatus == fission.BuildStatusNone { + if pkg.Status.BuildStatus == types.BuildStatusNone { continue } - if pkg.Status.BuildStatus == fission.BuildStatusPending || - pkg.Status.BuildStatus == fission.BuildStatusRunning { + if pkg.Status.BuildStatus == types.BuildStatusPending || + pkg.Status.BuildStatus == types.BuildStatusRunning { keepWaiting = true } buildpkgs = append(buildpkgs, pkg) @@ -95,10 +95,10 @@ func (w *packageBuildWatcher) watch(ctx context.Context) { if _, printed := w.finished[k]; printed { continue } - if pkg.Status.BuildStatus == fission.BuildStatusFailed { + if pkg.Status.BuildStatus == types.BuildStatusFailed { w.finished[k] = true fmt.Printf("--- Build FAILED: ---\n%v\n------\n", pkg.Status.BuildLog) - } else if pkg.Status.BuildStatus == fission.BuildStatusSucceeded { + } else if pkg.Status.BuildStatus == types.BuildStatusSucceeded { w.finished[k] = true fmt.Printf("--- Build SUCCEEDED ---\n") if len(pkg.Status.BuildLog) > 0 { @@ -115,7 +115,7 @@ func (w *packageBuildWatcher) watch(ctx context.Context) { } } -func pkgKey(pkg *crd.Package) string { +func pkgKey(pkg *fv1.Package) string { // packages are mutable so we want to keep track of them by resource version return fmt.Sprintf("%v:%v:%v", pkg.Metadata.Name, pkg.Metadata.Namespace, pkg.Metadata.ResourceVersion) } diff --git a/fission/canaryconfig.go b/pkg/fission-cli/canaryconfig.go similarity index 92% rename from fission/canaryconfig.go rename to pkg/fission-cli/canaryconfig.go index 4ba318e9..1ebc645a 100644 --- a/fission/canaryconfig.go +++ b/pkg/fission-cli/canaryconfig.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -25,10 +25,10 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/types" ) func canaryConfigCreate(c *cli.Context) error { @@ -64,7 +64,7 @@ func canaryConfigCreate(c *cli.Context) error { } // check that the trigger has function reference type function weights - if htTrigger.Spec.FunctionReference.Type != fission.FunctionReferenceTypeFunctionWeights { + if htTrigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionWeights { log.Fatal("Canary config cannot be created for http triggers that do not reference functions by weights") } @@ -87,22 +87,22 @@ func canaryConfigCreate(c *cli.Context) error { } // finally create canaryCfg in the same namespace as the functions referenced - canaryCfg := &crd.CanaryConfig{ + canaryCfg := &fv1.CanaryConfig{ Metadata: metav1.ObjectMeta{ Name: canaryConfigName, Namespace: ns, }, - Spec: fission.CanaryConfigSpec{ + Spec: fv1.CanaryConfigSpec{ Trigger: trigger, NewFunction: newFunc, OldFunction: oldFunc, WeightIncrement: incrementStep, WeightIncrementDuration: incrementInterval, FailureThreshold: failureThreshold, - FailureType: fission.FailureTypeStatusCode, + FailureType: fv1.FailureTypeStatusCode, }, - Status: fission.CanaryConfigStatus{ - Status: fission.CanaryConfigStatusPending, + Status: fv1.CanaryConfigStatus{ + Status: fv1.CanaryConfigStatusPending, }, } @@ -183,7 +183,7 @@ func canaryConfigUpdate(c *cli.Context) error { } if updateNeeded { - canaryCfg.Status.Status = fission.CanaryConfigStatusPending + canaryCfg.Status.Status = fv1.CanaryConfigStatusPending _, err = client.CanaryConfigUpdate(canaryCfg) util.CheckErr(err, "update canary config") diff --git a/fission/environment.go b/pkg/fission-cli/environment.go similarity index 95% rename from fission/environment.go rename to pkg/fission-cli/environment.go index e7658212..d077d363 100644 --- a/fission/environment.go +++ b/pkg/fission-cli/environment.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -22,24 +22,23 @@ import ( "strconv" "text/tabwriter" - "github.com/fission/fission/fission/util" "github.com/urfave/cli" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" ) -func getFunctionsByEnvironment(client *client.Client, envName, envNamespace string) ([]crd.Function, error) { +func getFunctionsByEnvironment(client *client.Client, envName, envNamespace string) ([]fv1.Function, error) { fnList, err := client.FunctionList(metav1.NamespaceAll) if err != nil { return nil, err } - fns := []crd.Function{} + fns := []fv1.Function{} for _, fn := range fnList { if fn.Spec.Environment.Name == envName && fn.Spec.Environment.Namespace == envNamespace { fns = append(fns, fn) @@ -107,17 +106,17 @@ func envCreate(c *cli.Context) error { resourceReq := getResourceReq(c, v1.ResourceRequirements{}) - env := &crd.Environment{ + env := &fv1.Environment{ Metadata: metav1.ObjectMeta{ Name: envName, Namespace: envNamespace, }, - Spec: fission.EnvironmentSpec{ + Spec: fv1.EnvironmentSpec{ Version: envVersion, - Runtime: fission.Runtime{ + Runtime: fv1.Runtime{ Image: envImg, }, - Builder: fission.Builder{ + Builder: fv1.Builder{ Image: envBuilderImg, Command: envBuildCmd, }, diff --git a/fission/function.go b/pkg/fission-cli/function.go similarity index 92% rename from fission/function.go rename to pkg/fission-cli/function.go index d39428b7..d52968ba 100644 --- a/fission/function.go +++ b/pkg/fission-cli/function.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "context" @@ -28,17 +28,18 @@ import ( "text/tabwriter" "time" + "github.com/fission/fission/pkg/types" "github.com/satori/go.uuid" "github.com/urfave/cli" apiv1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/logdb" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/logdb" + "github.com/fission/fission/pkg/fission-cli/util" ) const ( @@ -74,17 +75,17 @@ func printPodLogs(c *cli.Context) error { return nil } -func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fission.InvokeStrategy) (strategy *fission.InvokeStrategy, err error) { +func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fv1.InvokeStrategy) (strategy *fv1.InvokeStrategy, err error) { - var fnExecutor, newFnExecutor fission.ExecutorType + var fnExecutor, newFnExecutor fv1.ExecutorType switch c.String("executortype") { case "": fallthrough - case fission.ExecutorTypePoolmgr: - newFnExecutor = fission.ExecutorTypePoolmgr - case fission.ExecutorTypeNewdeploy: - newFnExecutor = fission.ExecutorTypeNewdeploy + case types.ExecutorTypePoolmgr: + newFnExecutor = types.ExecutorTypePoolmgr + case types.ExecutorTypeNewdeploy: + newFnExecutor = types.ExecutorTypeNewdeploy default: return nil, errors.New("Executor type must be one of 'poolmgr' or 'newdeploy', defaults to 'poolmgr'") } @@ -100,7 +101,7 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fission.InvokeStr fnExecutor = newFnExecutor } - if fnExecutor == fission.ExecutorTypePoolmgr { + if fnExecutor == types.ExecutorTypePoolmgr { if c.IsSet("targetcpu") || c.IsSet("minscale") || c.IsSet("maxscale") { log.Fatal("To set target CPU or min/max scale for function, please specify \"--executortype newdeploy\"") } @@ -108,10 +109,10 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fission.InvokeStr if c.IsSet("mincpu") || c.IsSet("maxcpu") || c.IsSet("minmemory") || c.IsSet("maxmemory") { log.Warn("To limit CPU/Memory for function with executor type \"poolmgr\", please specify resources limits when creating environment") } - strategy = &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypePoolmgr, + strategy = &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: types.ExecutorTypePoolmgr, }, } } else { @@ -120,7 +121,7 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fission.InvokeStr minScale := DEFAULT_MIN_SCALE maxScale := minScale - if existingInvokeStrategy != nil && existingInvokeStrategy.ExecutionStrategy.ExecutorType == fission.ExecutorTypeNewdeploy { + if existingInvokeStrategy != nil && existingInvokeStrategy.ExecutionStrategy.ExecutorType == types.ExecutorTypeNewdeploy { minScale = existingInvokeStrategy.ExecutionStrategy.MinScale maxScale = existingInvokeStrategy.ExecutionStrategy.MaxScale targetCPU = existingInvokeStrategy.ExecutionStrategy.TargetCPUPercent @@ -147,9 +148,9 @@ func getInvokeStrategy(c *cli.Context, existingInvokeStrategy *fission.InvokeStr // Right now a simple single case strategy implementation // This will potentially get more sophisticated once we have more strategies in place - strategy = &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ + strategy = &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ ExecutorType: fnExecutor, MinScale: minScale, MaxScale: maxScale, @@ -245,7 +246,7 @@ func fnCreate(c *cli.Context) error { Name: envName, }) if err != nil { - if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNotFound { + if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNotFound { log.Warn(fmt.Sprintf("Environment \"%v\" does not exist. Please create the environment before executing the function. \nFor example: `fission env create --name %v --envns %v --image `\n", envName, envName, envNamespace)) } else { util.CheckErr(err, "retrieve environment information") @@ -274,8 +275,8 @@ func fnCreate(c *cli.Context) error { pkgMetadata = createPackage(client, fnNamespace, envName, envNamespace, srcArchiveFiles, deployArchiveFiles, buildcmd, specDir, specFile, noZip) } - var secrets []fission.SecretReference - var cfgmaps []fission.ConfigMapReference + var secrets []fv1.SecretReference + var cfgmaps []fv1.ConfigMapReference if len(secretName) > 0 { // check the referenced secret is in the same ns as the function, if not give a warning. @@ -287,11 +288,11 @@ func fnCreate(c *cli.Context) error { log.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace)) } - newSecret := fission.SecretReference{ + newSecret := fv1.SecretReference{ Name: secretName, Namespace: fnNamespace, } - secrets = []fission.SecretReference{newSecret} + secrets = []fv1.SecretReference{newSecret} } if len(cfgMapName) > 0 { @@ -304,26 +305,26 @@ func fnCreate(c *cli.Context) error { log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace)) } - newCfgMap := fission.ConfigMapReference{ + newCfgMap := fv1.ConfigMapReference{ Name: cfgMapName, Namespace: fnNamespace, } - cfgmaps = []fission.ConfigMapReference{newCfgMap} + cfgmaps = []fv1.ConfigMapReference{newCfgMap} } - function := &crd.Function{ + function := &fv1.Function{ Metadata: metav1.ObjectMeta{ Name: fnName, Namespace: fnNamespace, }, - Spec: fission.FunctionSpec{ - Environment: fission.EnvironmentReference{ + Spec: fv1.FunctionSpec{ + Environment: fv1.EnvironmentReference{ Name: envName, Namespace: envNamespace, }, - Package: fission.FunctionPackageRef{ + Package: fv1.FunctionPackageRef{ FunctionName: entrypoint, - PackageRef: fission.PackageRef{ + PackageRef: fv1.PackageRef{ Namespace: pkgMetadata.Namespace, Name: pkgMetadata.Name, ResourceVersion: pkgMetadata.ResourceVersion, @@ -363,16 +364,16 @@ func fnCreate(c *cli.Context) error { method = http.MethodGet } triggerName := uuid.NewV4().String() - ht := &crd.HTTPTrigger{ + ht := &fv1.HTTPTrigger{ Metadata: metav1.ObjectMeta{ Name: triggerName, Namespace: fnNamespace, }, - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ RelativeURL: triggerUrl, Method: getMethod(method), - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: fnName, }, }, @@ -507,11 +508,11 @@ func fnUpdate(c *cli.Context) error { log.Warn(fmt.Sprintf("secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace)) } - newSecret := fission.SecretReference{ + newSecret := fv1.SecretReference{ Name: secretName, Namespace: fnNamespace, } - function.Spec.Secrets = []fission.SecretReference{newSecret} + function.Spec.Secrets = []fv1.SecretReference{newSecret} } if len(cfgMapName) > 0 { @@ -528,11 +529,11 @@ func fnUpdate(c *cli.Context) error { log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as the function", cfgMapName, fnNamespace)) } - newCfgMap := fission.ConfigMapReference{ + newCfgMap := fv1.ConfigMapReference{ Name: cfgMapName, Namespace: fnNamespace, } - function.Spec.ConfigMaps = []fission.ConfigMapReference{newCfgMap} + function.Spec.ConfigMaps = []fv1.ConfigMapReference{newCfgMap} } if len(envName) > 0 { @@ -593,7 +594,7 @@ func fnUpdate(c *cli.Context) error { // references a diff env than the spec // update function spec with new package metadata - function.Spec.Package.PackageRef = fission.PackageRef{ + function.Spec.Package.PackageRef = fv1.PackageRef{ Namespace: pkgMetadata.Namespace, Name: pkgMetadata.Name, ResourceVersion: pkgMetadata.ResourceVersion, diff --git a/fission/function_test.go b/pkg/fission-cli/function_test.go similarity index 51% rename from fission/function_test.go rename to pkg/fission-cli/function_test.go index aa41c932..74d87fd0 100644 --- a/fission/function_test.go +++ b/pkg/fission-cli/function_test.go @@ -1,4 +1,4 @@ -package main +package fission_cli import ( "flag" @@ -8,48 +8,48 @@ import ( "github.com/stretchr/testify/assert" "github.com/urfave/cli" - "github.com/fission/fission" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) func TestGetInvokeStrategy(t *testing.T) { cases := []struct { testArgs map[string]string - existingInvokeStrategy *fission.InvokeStrategy - expectedResult *fission.InvokeStrategy + existingInvokeStrategy *fv1.InvokeStrategy + expectedResult *fv1.InvokeStrategy expectError bool }{ { // case: use default executor poolmgr testArgs: map[string]string{}, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypePoolmgr, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypePoolmgr, }, }, expectError: false, }, { // case: executor type set to poolmgr - testArgs: map[string]string{"executortype": fission.ExecutorTypePoolmgr}, + testArgs: map[string]string{"executortype": fv1.ExecutorTypePoolmgr}, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypePoolmgr, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypePoolmgr, }, }, expectError: false, }, { // case: executor type set to newdeploy - testArgs: map[string]string{"executortype": fission.ExecutorTypeNewdeploy}, + testArgs: map[string]string{"executortype": fv1.ExecutorTypeNewdeploy}, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: DEFAULT_MIN_SCALE, MaxScale: DEFAULT_MIN_SCALE, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -59,17 +59,17 @@ func TestGetInvokeStrategy(t *testing.T) { }, { // case: executor type change from poolmgr to newdeploy - testArgs: map[string]string{"executortype": fission.ExecutorTypeNewdeploy}, - existingInvokeStrategy: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypePoolmgr, + testArgs: map[string]string{"executortype": fv1.ExecutorTypeNewdeploy}, + existingInvokeStrategy: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypePoolmgr, }, }, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: DEFAULT_MIN_SCALE, MaxScale: DEFAULT_MIN_SCALE, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -79,20 +79,20 @@ func TestGetInvokeStrategy(t *testing.T) { }, { // case: executor type change from newdeploy to poolmgr - testArgs: map[string]string{"executortype": fission.ExecutorTypePoolmgr}, - existingInvokeStrategy: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + testArgs: map[string]string{"executortype": fv1.ExecutorTypePoolmgr}, + existingInvokeStrategy: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: DEFAULT_MIN_SCALE, MaxScale: DEFAULT_MIN_SCALE, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, }, }, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypePoolmgr, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypePoolmgr, }, }, expectError: false, @@ -100,15 +100,15 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: minscale < maxscale testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "minscale": "2", "maxscale": "3", }, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 3, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -119,7 +119,7 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: minscale > maxscale testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "minscale": "5", "maxscale": "3", }, @@ -130,7 +130,7 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: maxscale not specified testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "minscale": "5", }, existingInvokeStrategy: nil, @@ -140,14 +140,14 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: minscale not specified testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "maxscale": "3", }, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: DEFAULT_MIN_SCALE, MaxScale: 3, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -158,7 +158,7 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: maxscale set to 0 testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "maxscale": "0", }, existingInvokeStrategy: nil, @@ -168,22 +168,22 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: maxscale set to 9 when existing is 5 testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "maxscale": "9", }, - existingInvokeStrategy: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + existingInvokeStrategy: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 5, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, }, }, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 9, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -194,21 +194,21 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: change nothing for existing strategy testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, }, - existingInvokeStrategy: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + existingInvokeStrategy: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 5, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, }, }, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 5, TargetCPUPercent: DEFAULT_TARGET_CPU_PERCENTAGE, @@ -219,14 +219,14 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: set target cpu percentage testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "targetcpu": "50", }, existingInvokeStrategy: nil, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: DEFAULT_MIN_SCALE, MaxScale: DEFAULT_MIN_SCALE, TargetCPUPercent: 50, @@ -237,22 +237,22 @@ func TestGetInvokeStrategy(t *testing.T) { { // case: change target cpu percentage testArgs: map[string]string{ - "executortype": fission.ExecutorTypeNewdeploy, + "executortype": fv1.ExecutorTypeNewdeploy, "targetcpu": "20", }, - existingInvokeStrategy: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + existingInvokeStrategy: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 5, TargetCPUPercent: 88, }, }, - expectedResult: &fission.InvokeStrategy{ - StrategyType: fission.StrategyTypeExecution, - ExecutionStrategy: fission.ExecutionStrategy{ - ExecutorType: fission.ExecutorTypeNewdeploy, + expectedResult: &fv1.InvokeStrategy{ + StrategyType: fv1.StrategyTypeExecution, + ExecutionStrategy: fv1.ExecutionStrategy{ + ExecutorType: fv1.ExecutorTypeNewdeploy, MinScale: 2, MaxScale: 5, TargetCPUPercent: 20, @@ -265,7 +265,7 @@ func TestGetInvokeStrategy(t *testing.T) { for i, c := range cases { fmt.Printf("=== Test Case %v ===\n", i) - app := newCliApp() + app := NewCliApp() set := flag.NewFlagSet("test-cmd", 0) ctx := cli.NewContext(app, set, nil) diff --git a/fission/httptrigger.go b/pkg/fission-cli/httptrigger.go similarity index 93% rename from fission/httptrigger.go rename to pkg/fission-cli/httptrigger.go index 0a1ea726..ff46755f 100644 --- a/fission/httptrigger.go +++ b/pkg/fission-cli/httptrigger.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -23,14 +23,13 @@ import ( "strings" "text/tabwriter" - "github.com/fission/fission/fission/util" "github.com/satori/go.uuid" "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" ) // returns one of http.Method* @@ -59,10 +58,10 @@ func getMethod(method string) string { return "" } -func setHtFunctionRef(functionList []string, functionWeightsList []int) (*fission.FunctionReference, error) { +func setHtFunctionRef(functionList []string, functionWeightsList []int) (*fv1.FunctionReference, error) { if len(functionList) == 1 { - return &fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + return &fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: functionList[0], }, nil } else if len(functionList) == 2 { @@ -80,8 +79,8 @@ func setHtFunctionRef(functionList []string, functionWeightsList []int) (*fissio functionWeights[functionList[index]] = functionWeightsList[index] } - return &fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionWeights, + return &fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionWeights, FunctionWeights: functionWeights, }, nil } @@ -151,12 +150,12 @@ func htCreate(c *cli.Context) error { triggerName = uuid.NewV4().String() } - ht := &crd.HTTPTrigger{ + ht := &fv1.HTTPTrigger{ Metadata: metav1.ObjectMeta{ Name: triggerName, Namespace: fnNamespace, }, - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ Host: host, RelativeURL: triggerUrl, Method: getMethod(method), @@ -199,7 +198,7 @@ func htGet(c *cli.Context) error { fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\n", "NAME", "UID", "METHOD", "RELATIVE-URL", "FUNCTION-REFERENCE-TYPE", "FUNCTION(s)") function := "" - if htTrigger.Spec.FunctionReference.Type == fission.FunctionReferenceTypeFunctionName { + if htTrigger.Spec.FunctionReference.Type == fv1.FunctionReferenceTypeFunctionName { function = htTrigger.Spec.FunctionReference.Name } else { for k, v := range htTrigger.Spec.FunctionReference.FunctionWeights { diff --git a/fission/log/log.go b/pkg/fission-cli/log/log.go similarity index 100% rename from fission/log/log.go rename to pkg/fission-cli/log/log.go diff --git a/fission/logdb/influxdb.go b/pkg/fission-cli/logdb/influxdb.go similarity index 97% rename from fission/logdb/influxdb.go rename to pkg/fission-cli/logdb/influxdb.go index a5667aab..b969e7e6 100644 --- a/fission/logdb/influxdb.go +++ b/pkg/fission-cli/logdb/influxdb.go @@ -28,8 +28,8 @@ import ( influxdbClient "github.com/influxdata/influxdb/client/v2" - "github.com/fission/fission" - "github.com/fission/fission/fission/log" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/fission-cli/log" ) const ( @@ -170,7 +170,7 @@ func (influx InfluxDB) query(query influxdbClient.Query) (*influxdbClient.Respon defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fission.MakeErrorFromHTTP(resp) + return nil, ferror.MakeErrorFromHTTP(resp) } // decode influxdb response diff --git a/fission/logdb/logdb.go b/pkg/fission-cli/logdb/logdb.go similarity index 100% rename from fission/logdb/logdb.go rename to pkg/fission-cli/logdb/logdb.go diff --git a/fission/main.go b/pkg/fission-cli/main.go similarity index 98% rename from fission/main.go rename to pkg/fission-cli/main.go index 34689b59..4eed3f57 100644 --- a/fission/main.go +++ b/pkg/fission-cli/main.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "encoding/json" @@ -27,11 +27,12 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/plugin" - "github.com/fission/fission/fission/support" - "github.com/fission/fission/fission/util" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/plugin" + "github.com/fission/fission/pkg/fission-cli/support" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/info" + "github.com/fission/fission/pkg/types" ) func cliHook(c *cli.Context) error { @@ -48,15 +49,11 @@ func cliHook(c *cli.Context) error { return nil } -func main() { - newCliApp().Run(os.Args) -} - -func newCliApp() *cli.App { +func NewCliApp() *cli.App { app := cli.NewApp() app.Name = "fission" app.Usage = "Serverless functions for Kubernetes" - app.Version = fission.Version + app.Version = info.Version cli.VersionPrinter = versionPrinter app.CustomAppHelpTemplate = helpTemplate app.ExtraInfo = func() map[string]string { @@ -118,7 +115,7 @@ func newCliApp() *cli.App { fnCfgMapFlag := cli.StringFlag{Name: "configmap", Usage: "function access to configmap, should be present in the same namespace as the function"} fnLogCountFlag := cli.StringFlag{Name: "recordcount", Usage: "the n most recent log records"} fnForceFlag := cli.BoolFlag{Name: "force", Usage: "Force update a package even if it is used by one or more functions"} - fnExecutorTypeFlag := cli.StringFlag{Name: "executortype", Value: fission.ExecutorTypePoolmgr, Usage: "Executor type for execution; one of 'poolmgr', 'newdeploy' defaults to 'poolmgr'"} + fnExecutorTypeFlag := cli.StringFlag{Name: "executortype", Value: types.ExecutorTypePoolmgr, Usage: "Executor type for execution; one of 'poolmgr', 'newdeploy' defaults to 'poolmgr'"} fnTimeoutFlag := cli.DurationFlag{Name: "timeout, t", Value: 30 * time.Second, Usage: "The length of time to wait for the response. If set to zero or negative number, no timeout is set."} fnSubcommands := []cli.Command{ @@ -339,7 +336,7 @@ func handleNoCommand(ctx *cli.Context) error { } if ctx.GlobalBool("plugin") { bs, err := json.Marshal(plugin.Metadata{ - Version: fission.Version, + Version: info.Version, Usage: ctx.App.Usage, }) if err != nil { diff --git a/fission/mqtrigger.go b/pkg/fission-cli/mqtrigger.go similarity index 88% rename from fission/mqtrigger.go rename to pkg/fission-cli/mqtrigger.go index ea47ce63..a481a318 100644 --- a/fission/mqtrigger.go +++ b/pkg/fission-cli/mqtrigger.go @@ -14,22 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" "os" "text/tabwriter" - "github.com/fission/fission/fission/util" "github.com/satori/go.uuid" "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/types" ) func mqtCreate(c *cli.Context) error { @@ -45,16 +44,16 @@ func mqtCreate(c *cli.Context) error { } fnNamespace := c.String("fnNamespace") - var mqType fission.MessageQueueType + var mqType fv1.MessageQueueType switch c.String("mqtype") { case "": - mqType = fission.MessageQueueTypeNats - case fission.MessageQueueTypeNats: - mqType = fission.MessageQueueTypeNats - case fission.MessageQueueTypeASQ: - mqType = fission.MessageQueueTypeASQ - case fission.MessageQueueTypeKafka: - mqType = fission.MessageQueueTypeKafka + mqType = types.MessageQueueTypeNats + case types.MessageQueueTypeNats: + mqType = types.MessageQueueTypeNats + case types.MessageQueueTypeASQ: + mqType = types.MessageQueueTypeASQ + case types.MessageQueueTypeKafka: + mqType = types.MessageQueueTypeKafka default: log.Fatal("Unknown message queue type, currently only \"nats-streaming, azure-storage-queue, kafka \" is supported") @@ -89,14 +88,14 @@ func mqtCreate(c *cli.Context) error { checkMQTopicAvailability(mqType, topic, respTopic) - mqt := &crd.MessageQueueTrigger{ + mqt := &fv1.MessageQueueTrigger{ Metadata: metav1.ObjectMeta{ Name: mqtName, Namespace: fnNamespace, }, - Spec: fission.MessageQueueTriggerSpec{ - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + Spec: fv1.MessageQueueTriggerSpec{ + FunctionReference: fv1.FunctionReference{ + Type: types.FunctionReferenceTypeFunctionName, Name: fnName, }, MessageQueueType: mqType, @@ -227,7 +226,7 @@ func mqtList(c *cli.Context) error { return nil } -func checkMQTopicAvailability(mqType fission.MessageQueueType, topics ...string) { +func checkMQTopicAvailability(mqType fv1.MessageQueueType, topics ...string) { for _, t := range topics { if len(t) > 0 && !fv1.IsTopicValid(mqType, t) { log.Fatal(fmt.Sprintf("Invalid topic for %s: %s", mqType, t)) diff --git a/fission/package.go b/pkg/fission-cli/package.go similarity index 90% rename from fission/package.go rename to pkg/fission-cli/package.go index c649ff0b..af873da4 100644 --- a/fission/package.go +++ b/pkg/fission-cli/package.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "bytes" @@ -33,8 +33,7 @@ import ( "text/tabwriter" "github.com/dchest/uniuri" - "github.com/fission/fission/fission/util" - storageSvcClient "github.com/fission/fission/storagesvc/client" + "github.com/fission/fission/pkg/utils" "github.com/hashicorp/go-multierror" "github.com/mholt/archiver" "github.com/pkg/errors" @@ -42,18 +41,20 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + storageSvcClient "github.com/fission/fission/pkg/storagesvc/client" + "github.com/fission/fission/pkg/types" ) -func getFunctionsByPackage(client *client.Client, pkgName, pkgNamespace string) ([]crd.Function, error) { +func getFunctionsByPackage(client *client.Client, pkgName, pkgNamespace string) ([]fv1.Function, error) { fnList, err := client.FunctionList(pkgNamespace) if err != nil { return nil, err } - fns := []crd.Function{} + fns := []fv1.Function{} for _, fn := range fnList { if fn.Spec.Package.PackageRef.Name == pkgName { fns = append(fns, fn) @@ -166,10 +167,10 @@ func pkgUpdate(c *cli.Context) error { return nil } -func updatePackage(client *client.Client, pkg *crd.Package, envName, envNamespace string, +func updatePackage(client *client.Client, pkg *fv1.Package, envName, envNamespace string, srcArchiveFiles []string, deployArchiveFiles []string, buildcmd string, forceRebuild bool, noZip bool) (*metav1.ObjectMeta, error) { - var srcArchiveMetadata, deployArchiveMetadata *fission.Archive + var srcArchiveMetadata, deployArchiveMetadata *fv1.Archive needToBuild := false if len(envName) > 0 { @@ -204,8 +205,8 @@ func updatePackage(client *client.Client, pkg *crd.Package, envName, envNamespac // Set package as pending status when needToBuild is true if needToBuild || forceRebuild { // change into pending state to trigger package build - pkg.Status = fission.PackageStatus{ - BuildStatus: fission.BuildStatusPending, + pkg.Status = fv1.PackageStatus{ + BuildStatus: fv1.BuildStatusPending, } } @@ -236,9 +237,9 @@ func pkgSourceGet(c *cli.Context) error { var reader io.Reader - if pkg.Spec.Source.Type == fission.ArchiveTypeLiteral { + if pkg.Spec.Source.Type == fv1.ArchiveTypeLiteral { reader = bytes.NewReader(pkg.Spec.Source.Literal) - } else if pkg.Spec.Source.Type == fission.ArchiveTypeUrl { + } else if pkg.Spec.Source.Type == fv1.ArchiveTypeUrl { readCloser := downloadStoragesvcURL(client, pkg.Spec.Source.URL) defer readCloser.Close() reader = readCloser @@ -273,9 +274,9 @@ func pkgDeployGet(c *cli.Context) error { var reader io.Reader - if pkg.Spec.Deployment.Type == fission.ArchiveTypeLiteral { + if pkg.Spec.Deployment.Type == fv1.ArchiveTypeLiteral { reader = bytes.NewReader(pkg.Spec.Deployment.Literal) - } else if pkg.Spec.Deployment.Type == fission.ArchiveTypeUrl { + } else if pkg.Spec.Deployment.Type == fv1.ArchiveTypeUrl { readCloser := downloadStoragesvcURL(client, pkg.Spec.Deployment.URL) defer readCloser.Close() reader = readCloser @@ -437,9 +438,9 @@ func pkgRebuild(c *cli.Context) error { }) util.CheckErr(err, "find package") - if pkg.Status.BuildStatus != fission.BuildStatusFailed { + if pkg.Status.BuildStatus != fv1.BuildStatusFailed { log.Fatal(fmt.Sprintf("Package %v is not in %v state.", - pkg.Metadata.Name, fission.BuildStatusFailed)) + pkg.Metadata.Name, fv1.BuildStatusFailed)) } _, err = updatePackage(client, pkg, "", "", nil, nil, "", true, false) @@ -456,7 +457,7 @@ func fileSize(filePath string) int64 { return info.Size() } -func fileChecksum(fileName string) (*fission.Checksum, error) { +func fileChecksum(fileName string) (*fv1.Checksum, error) { f, err := os.Open(fileName) if err != nil { return nil, fmt.Errorf("failed to open file %v: %v", fileName, err) @@ -469,17 +470,17 @@ func fileChecksum(fileName string) (*fission.Checksum, error) { return nil, fmt.Errorf("failed to calculate checksum for %v", fileName) } - return &fission.Checksum{ - Type: fission.ChecksumTypeSHA256, + return &fv1.Checksum{ + Type: fv1.ChecksumTypeSHA256, Sum: hex.EncodeToString(h.Sum(nil)), }, nil } -// Return a fission.Archive made from an archive . If specFile, then +// Return a fv1.Archive made from an archive . If specFile, then // create an archive upload spec in the specs directory; otherwise // upload the archive using client. noZip avoids zipping the // includeFiles, but is ignored if there's more than one includeFile. -func createArchive(client *client.Client, includeFiles []string, noZip bool, specDir string, specFile string) *fission.Archive { +func createArchive(client *client.Client, includeFiles []string, noZip bool, specDir string, specFile string) *fv1.Archive { var errs *multierror.Error @@ -491,7 +492,7 @@ func createArchive(client *client.Client, includeFiles []string, noZip bool, spe } // Get files from inputs as number of files decide next steps - files, err := fission.FindAllGlobs([]string{path}) + files, err := utils.FindAllGlobs([]string{path}) if err != nil { util.CheckErr(err, "finding all globs") } @@ -525,8 +526,8 @@ func createArchive(client *client.Client, includeFiles []string, noZip bool, spe } // create the archive object - ar := &fission.Archive{ - Type: fission.ArchiveTypeUrl, + ar := &fv1.Archive{ + Type: fv1.ArchiveTypeUrl, URL: fmt.Sprintf("%v%v", ARCHIVE_URL_PREFIX, aus.Name), } return ar @@ -538,16 +539,16 @@ func createArchive(client *client.Client, includeFiles []string, noZip bool, spe return uploadArchive(ctx, client, archivePath) } -func uploadArchive(ctx context.Context, client *client.Client, fileName string) *fission.Archive { - var archive fission.Archive +func uploadArchive(ctx context.Context, client *client.Client, fileName string) *fv1.Archive { + var archive fv1.Archive // If filename is a URL, download it first if strings.HasPrefix(fileName, "http://") || strings.HasPrefix(fileName, "https://") { fileName = downloadToTempFile(fileName) } - if fileSize(fileName) < fission.ArchiveLiteralSizeLimit { - archive.Type = fission.ArchiveTypeLiteral + if fileSize(fileName) < types.ArchiveLiteralSizeLimit { + archive.Type = fv1.ArchiveTypeLiteral archive.Literal = getContents(fileName) } else { u := strings.TrimSuffix(client.Url, "/") + "/proxy/storage" @@ -566,7 +567,7 @@ func uploadArchive(ctx context.Context, client *client.Client, fileName string) pkgClient := storageSvcClient.MakeClient(storageSvcURL) archiveURL := pkgClient.GetUrl(id) - archive.Type = fission.ArchiveTypeUrl + archive.Type = fv1.ArchiveTypeUrl archive.URL = archiveURL csum, err := fileChecksum(fileName) @@ -578,25 +579,25 @@ func uploadArchive(ctx context.Context, client *client.Client, fileName string) } func createPackage(client *client.Client, pkgNamespace string, envName string, envNamespace string, srcArchiveFiles []string, deployArchiveFiles []string, buildcmd string, specDir string, specFile string, noZip bool) *metav1.ObjectMeta { - pkgSpec := fission.PackageSpec{ - Environment: fission.EnvironmentReference{ + pkgSpec := fv1.PackageSpec{ + Environment: fv1.EnvironmentReference{ Namespace: envNamespace, Name: envName, }, } - var pkgStatus fission.BuildStatus = fission.BuildStatusSucceeded + var pkgStatus fv1.BuildStatus = fv1.BuildStatusSucceeded var pkgName string if len(deployArchiveFiles) > 0 { if len(specFile) > 0 { // we should do this in all cases, i think - pkgStatus = fission.BuildStatusNone + pkgStatus = fv1.BuildStatusNone } pkgSpec.Deployment = *createArchive(client, deployArchiveFiles, noZip, specDir, specFile) pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(deployArchiveFiles[0]), uniuri.NewLen(4))) } if len(srcArchiveFiles) > 0 { pkgSpec.Source = *createArchive(client, srcArchiveFiles, false, specDir, specFile) - pkgStatus = fission.BuildStatusPending // set package build status to pending + pkgStatus = fv1.BuildStatusPending // set package build status to pending pkgName = util.KubifyName(fmt.Sprintf("%v-%v", path.Base(srcArchiveFiles[0]), uniuri.NewLen(4))) } @@ -607,13 +608,13 @@ func createPackage(client *client.Client, pkgNamespace string, envName string, e if len(pkgName) == 0 { pkgName = strings.ToLower(uuid.NewV4().String()) } - pkg := &crd.Package{ + pkg := &fv1.Package{ Metadata: metav1.ObjectMeta{ Name: pkgName, Namespace: pkgNamespace, }, Spec: pkgSpec, - Status: fission.PackageStatus{ + Status: fv1.PackageStatus{ BuildStatus: pkgStatus, }, } @@ -648,7 +649,7 @@ func getContents(filePath string) []byte { } func writeArchiveToFile(fileName string, reader io.Reader) error { - tmpDir, err := fission.GetTempDir() + tmpDir, err := utils.GetTempDir() if err != nil { return err } @@ -682,7 +683,7 @@ func downloadToTempFile(fileUrl string) string { defer reader.Close() util.CheckErr(err, fmt.Sprintf("download from url: %v", fileUrl)) - tmpDir, err := fission.GetTempDir() + tmpDir, err := utils.GetTempDir() util.CheckErr(err, "create temp directory") tmpFilename := uuid.NewV4().String() @@ -721,7 +722,7 @@ func makeArchiveFileIfNeeded(archiveNameHint string, archiveInput []string, noZi archiveName := archiveName(archiveNameHint, archiveInput) // Get files from inputs as number of files decide next steps - files, err := fission.FindAllGlobs(archiveInput) + files, err := utils.FindAllGlobs(archiveInput) if err != nil { util.CheckErr(err, "finding all globs") } @@ -745,12 +746,12 @@ func makeArchiveFileIfNeeded(archiveNameHint string, archiveInput []string, noZi } // For anything else, create a new archive - tmpDir, err := fission.GetTempDir() + tmpDir, err := utils.GetTempDir() if err != nil { util.CheckErr(err, "create temporary archive directory") } - archivePath, err := fission.MakeArchive(filepath.Join(tmpDir, archiveName), archiveInput...) + archivePath, err := utils.MakeArchive(filepath.Join(tmpDir, archiveName), archiveInput...) if err != nil { util.CheckErr(err, "create archive file") } diff --git a/fission/plugin.go b/pkg/fission-cli/plugin.go similarity index 94% rename from fission/plugin.go rename to pkg/fission-cli/plugin.go index 97c8c9aa..3825f848 100644 --- a/fission/plugin.go +++ b/pkg/fission-cli/plugin.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -23,7 +23,7 @@ import ( "github.com/urfave/cli" - "github.com/fission/fission/fission/plugin" + "github.com/fission/fission/pkg/fission-cli/plugin" ) var cmdPlugin = cli.Command{ diff --git a/fission/plugin/plugin.go b/pkg/fission-cli/plugin/plugin.go similarity index 100% rename from fission/plugin/plugin.go rename to pkg/fission-cli/plugin/plugin.go diff --git a/fission/plugin/plugin_test.go b/pkg/fission-cli/plugin/plugin_test.go similarity index 100% rename from fission/plugin/plugin_test.go rename to pkg/fission-cli/plugin/plugin_test.go diff --git a/fission/plugin/registry.go b/pkg/fission-cli/plugin/registry.go similarity index 100% rename from fission/plugin/registry.go rename to pkg/fission-cli/plugin/registry.go diff --git a/fission/recorder.go b/pkg/fission-cli/recorder.go similarity index 96% rename from fission/recorder.go rename to pkg/fission-cli/recorder.go index 71034339..cfc7e17c 100644 --- a/fission/recorder.go +++ b/pkg/fission-cli/recorder.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -26,10 +26,9 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" ) func recorderCreate(c *cli.Context) error { @@ -63,12 +62,12 @@ func recorderCreate(c *cli.Context) error { //retPolicy := c.String("retention") //evictPolicy := c.String("eviction") - recorder := &crd.Recorder{ + recorder := &fv1.Recorder{ Metadata: metav1.ObjectMeta{ Name: recName, Namespace: "default", }, - Spec: fission.RecorderSpec{ + Spec: fv1.RecorderSpec{ Name: recName, Function: fnName, Triggers: triggers, diff --git a/fission/records.go b/pkg/fission-cli/records.go similarity index 95% rename from fission/records.go rename to pkg/fission-cli/records.go index 525a4ced..2fa7bda1 100644 --- a/fission/records.go +++ b/pkg/fission-cli/records.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -23,9 +23,9 @@ import ( "github.com/urfave/cli" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" - "github.com/fission/fission/redis/build/gen" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/redis/build/gen" ) func recordsView(c *cli.Context) error { diff --git a/fission/replay.go b/pkg/fission-cli/replay.go similarity index 89% rename from fission/replay.go rename to pkg/fission-cli/replay.go index e51a8416..68e71d0c 100644 --- a/fission/replay.go +++ b/pkg/fission-cli/replay.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" "os" "text/tabwriter" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" "github.com/urfave/cli" ) diff --git a/fission/spec.go b/pkg/fission-cli/spec.go similarity index 94% rename from fission/spec.go rename to pkg/fission-cli/spec.go index 51396323..40413c2a 100644 --- a/fission/spec.go +++ b/pkg/fission-cli/spec.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "bytes" @@ -36,14 +36,14 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/types" ) -const SPEC_API_VERSION = "fission.io/v1" +const SPEC_API_VERSION = "fv1.io/v1" const ARCHIVE_URL_PREFIX string = "archive://" @@ -87,20 +87,20 @@ resources on the cluster to resources in this directory. All resources created by 'fission spec apply' are annotated with this UID. Resources on the cluster that are _not_ annotated with this UID are never modified or deleted by -fission. +fv1. ` type ( FissionResources struct { deploymentConfig DeploymentConfig - packages []crd.Package - functions []crd.Function - environments []crd.Environment - httpTriggers []crd.HTTPTrigger - kubernetesWatchTriggers []crd.KubernetesWatchTrigger - timeTriggers []crd.TimeTrigger - messageQueueTriggers []crd.MessageQueueTrigger + packages []fv1.Package + functions []fv1.Function + environments []fv1.Environment + httpTriggers []fv1.HTTPTrigger + kubernetesWatchTriggers []fv1.KubernetesWatchTrigger + timeTriggers []fv1.TimeTrigger + messageQueueTriggers []fv1.MessageQueueTrigger archiveUploadSpecs []ArchiveUploadSpec sourceMap sourceMap @@ -202,8 +202,8 @@ func specInit(c *cli.Context) error { } // validateFunctionReference checks a function reference -func (fr *FissionResources) validateFunctionReference(functions map[string]bool, kind string, meta *metav1.ObjectMeta, funcRef fission.FunctionReference) error { - if funcRef.Type == fission.FunctionReferenceTypeFunctionName { +func (fr *FissionResources) validateFunctionReference(functions map[string]bool, kind string, meta *metav1.ObjectMeta, funcRef fv1.FunctionReference) error { + if funcRef.Type == fv1.FunctionReferenceTypeFunctionName { // triggers only reference functions in their own namespace namespace := meta.Namespace name := funcRef.Name @@ -321,7 +321,7 @@ func (fr *FissionResources) validate() error { } // check that the package referenced by each function is in the same ns as the function - packageRefInFuncNs := func(f *crd.Function) bool { + packageRefInFuncNs := func(f *fv1.Function) bool { return f.Spec.Package.PackageRef.Namespace == f.Metadata.Namespace } @@ -446,7 +446,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { err := yaml.Unmarshal(b, &tm) switch tm.Kind { case "Package": - var v crd.Package + var v fv1.Package err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -454,7 +454,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.packages = append(fr.packages, v) case "Function": - var v crd.Function + var v fv1.Function err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -462,7 +462,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.functions = append(fr.functions, v) case "Environment": - var v crd.Environment + var v fv1.Environment err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -470,7 +470,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.environments = append(fr.environments, v) case "HTTPTrigger": - var v crd.HTTPTrigger + var v fv1.HTTPTrigger err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -484,7 +484,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.httpTriggers = append(fr.httpTriggers, v) case "KubernetesWatchTrigger": - var v crd.KubernetesWatchTrigger + var v fv1.KubernetesWatchTrigger err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -492,7 +492,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.kubernetesWatchTriggers = append(fr.kubernetesWatchTriggers, v) case "TimeTrigger": - var v crd.TimeTrigger + var v fv1.TimeTrigger err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -500,7 +500,7 @@ func (fr *FissionResources) parseYaml(b []byte, loc *location) error { m = &v.Metadata fr.timeTriggers = append(fr.timeTriggers, v) case "MessageQueueTrigger": - var v crd.MessageQueueTrigger + var v fv1.MessageQueueTrigger err = yaml.Unmarshal(b, &v) if err != nil { return errors.Wrap(err, fmt.Sprintf("Failed to parse %v in %v", tm.Kind, loc)) @@ -556,13 +556,13 @@ func readSpecs(specDir string) (*FissionResources, error) { } fr := FissionResources{ - packages: make([]crd.Package, 0), - functions: make([]crd.Function, 0), - environments: make([]crd.Environment, 0), - httpTriggers: make([]crd.HTTPTrigger, 0), - kubernetesWatchTriggers: make([]crd.KubernetesWatchTrigger, 0), - timeTriggers: make([]crd.TimeTrigger, 0), - messageQueueTriggers: make([]crd.MessageQueueTrigger, 0), + packages: make([]fv1.Package, 0), + functions: make([]fv1.Function, 0), + environments: make([]fv1.Environment, 0), + httpTriggers: make([]fv1.HTTPTrigger, 0), + kubernetesWatchTriggers: make([]fv1.KubernetesWatchTrigger, 0), + timeTriggers: make([]fv1.TimeTrigger, 0), + messageQueueTriggers: make([]fv1.MessageQueueTrigger, 0), sourceMap: sourceMap{ locations: make(map[string](map[string](map[string]location))), @@ -818,7 +818,7 @@ func specDestroy(c *cli.Context) error { func applyArchives(fclient *client.Client, specDir string, fr *FissionResources) error { // archive:// URL -> archive map. - archiveFiles := make(map[string]fission.Archive) + archiveFiles := make(map[string]fv1.Archive) // We'll first populate archiveFiles with references to local files, and then modify it to // point at archive URLs. @@ -840,8 +840,8 @@ func applyArchives(fclient *client.Client, specDir string, fr *FissionResources) return err } for _, pkg := range pkgs { - for _, ar := range []fission.Archive{pkg.Spec.Source, pkg.Spec.Deployment} { - if ar.Type == fission.ArchiveTypeUrl && len(ar.URL) > 0 { + for _, ar := range []fv1.Archive{pkg.Spec.Source, pkg.Spec.Deployment} { + if ar.Type == fv1.ArchiveTypeUrl && len(ar.URL) > 0 { availableArchives[ar.Checksum.Sum] = ar.URL } } @@ -849,7 +849,7 @@ func applyArchives(fclient *client.Client, specDir string, fr *FissionResources) // upload archives that we need to, updating the map for name, ar := range archiveFiles { - if ar.Type == fission.ArchiveTypeLiteral { + if ar.Type == fv1.ArchiveTypeLiteral { continue } // does the archive exist already? @@ -869,7 +869,7 @@ func applyArchives(fclient *client.Client, specDir string, fr *FissionResources) // resolve references to urls in packages to be applied for i := range fr.packages { - for _, ar := range []*fission.Archive{&fr.packages[i].Spec.Source, &fr.packages[i].Spec.Deployment} { + for _, ar := range []*fv1.Archive{&fr.packages[i].Spec.Source, &fr.packages[i].Spec.Deployment} { if strings.HasPrefix(ar.URL, ARCHIVE_URL_PREFIX) { availableAr, ok := archiveFiles[ar.URL] if !ok { @@ -963,7 +963,7 @@ func applyResources(fclient *client.Client, specDir string, fr *FissionResources // localArchiveFromSpec creates an archive on the local filesystem from the given spec, // and returns its path and checksum. -func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fission.Archive, error) { +func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fv1.Archive, error) { // get root dir var rootDir string if len(aus.RootDir) == 0 { @@ -1026,10 +1026,10 @@ func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fission.Arch } // figure out if we're making a literal or a URL-based archive - if fileSize(archiveFileName) < fission.ArchiveLiteralSizeLimit { + if fileSize(archiveFileName) < types.ArchiveLiteralSizeLimit { contents := getContents(archiveFileName) - return &fission.Archive{ - Type: fission.ArchiveTypeLiteral, + return &fv1.Archive{ + Type: fv1.ArchiveTypeLiteral, Literal: contents, }, nil } else { @@ -1040,8 +1040,8 @@ func localArchiveFromSpec(specDir string, aus *ArchiveUploadSpec) (*fission.Arch } // archive object - return &fission.Archive{ - Type: fission.ArchiveTypeUrl, + return &fv1.Archive{ + Type: fv1.ArchiveTypeUrl, // we should be actually be adding a "file://" prefix, but this archive is only an // intermediate step, so just the path works fine. URL: archiveFileName, @@ -1080,10 +1080,10 @@ func hasDeploymentConfig(m *metav1.ObjectMeta, fr *FissionResources) bool { return false } -func waitForPackageBuild(fclient *client.Client, pkg *crd.Package) (*crd.Package, error) { +func waitForPackageBuild(fclient *client.Client, pkg *fv1.Package) (*fv1.Package, error) { start := time.Now() for { - if pkg.Status.BuildStatus != fission.BuildStatusRunning { + if pkg.Status.BuildStatus != fv1.BuildStatusRunning { return pkg, nil } if time.Since(start) > 5*time.Minute { @@ -1109,7 +1109,7 @@ func applyPackages(fclient *client.Client, fr *FissionResources, delete bool) (m } // filter - objs := make([]crd.Package, 0) + objs := make([]fv1.Package, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1117,7 +1117,7 @@ func applyPackages(fclient *client.Client, fr *FissionResources, delete bool) (m } // index - existent := make(map[string]crd.Package) + existent := make(map[string]fv1.Package) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1144,7 +1144,7 @@ func applyPackages(fclient *client.Client, fr *FissionResources, delete bool) (m if reflect.DeepEqual(existingObj.Spec, o.Spec) { keep = true } else if reflect.DeepEqual(existingObj.Spec.Environment, o.Spec.Environment) && - !reflect.DeepEqual(existingObj.Spec.Source, fission.Archive{}) && + !reflect.DeepEqual(existingObj.Spec.Source, fv1.Archive{}) && reflect.DeepEqual(existingObj.Spec.Source, o.Spec.Source) && existingObj.Spec.BuildCommand == o.Spec.BuildCommand { @@ -1214,7 +1214,7 @@ func applyFunctions(fclient *client.Client, fr *FissionResources, delete bool) ( } // filter - objs := make([]crd.Function, 0) + objs := make([]fv1.Function, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1222,7 +1222,7 @@ func applyFunctions(fclient *client.Client, fr *FissionResources, delete bool) ( } // index - existent := make(map[string]crd.Function) + existent := make(map[string]fv1.Function) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1297,7 +1297,7 @@ func applyEnvironments(fclient *client.Client, fr *FissionResources, delete bool } // filter - objs := make([]crd.Environment, 0) + objs := make([]fv1.Environment, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1305,7 +1305,7 @@ func applyEnvironments(fclient *client.Client, fr *FissionResources, delete bool } // index - existent := make(map[string]crd.Environment) + existent := make(map[string]fv1.Environment) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1380,7 +1380,7 @@ func applyHTTPTriggers(fclient *client.Client, fr *FissionResources, delete bool } // filter - objs := make([]crd.HTTPTrigger, 0) + objs := make([]fv1.HTTPTrigger, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1388,7 +1388,7 @@ func applyHTTPTriggers(fclient *client.Client, fr *FissionResources, delete bool } // index - existent := make(map[string]crd.HTTPTrigger) + existent := make(map[string]fv1.HTTPTrigger) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1463,7 +1463,7 @@ func applyKubernetesWatchTriggers(fclient *client.Client, fr *FissionResources, } // filter - objs := make([]crd.KubernetesWatchTrigger, 0) + objs := make([]fv1.KubernetesWatchTrigger, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1471,7 +1471,7 @@ func applyKubernetesWatchTriggers(fclient *client.Client, fr *FissionResources, } // index - existent := make(map[string]crd.KubernetesWatchTrigger) + existent := make(map[string]fv1.KubernetesWatchTrigger) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1546,7 +1546,7 @@ func applyTimeTriggers(fclient *client.Client, fr *FissionResources, delete bool } // filter - objs := make([]crd.TimeTrigger, 0) + objs := make([]fv1.TimeTrigger, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1554,7 +1554,7 @@ func applyTimeTriggers(fclient *client.Client, fr *FissionResources, delete bool } // index - existent := make(map[string]crd.TimeTrigger) + existent := make(map[string]fv1.TimeTrigger) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1629,7 +1629,7 @@ func applyMessageQueueTriggers(fclient *client.Client, fr *FissionResources, del } // filter - objs := make([]crd.MessageQueueTrigger, 0) + objs := make([]fv1.MessageQueueTrigger, 0) for _, o := range allObjs { if hasDeploymentConfig(&o.Metadata, fr) { objs = append(objs, o) @@ -1637,7 +1637,7 @@ func applyMessageQueueTriggers(fclient *client.Client, fr *FissionResources, del } // index - existent := make(map[string]crd.MessageQueueTrigger) + existent := make(map[string]fv1.MessageQueueTrigger) for _, obj := range objs { existent[mapKey(&obj.Metadata)] = obj } @@ -1720,35 +1720,35 @@ func specSave(resource interface{}, specFile string) error { case ArchiveUploadSpec: typedres.Kind = "ArchiveUploadSpec" data, err = yaml.Marshal(typedres) - case crd.Package: + case fv1.Package: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "Package" data, err = yaml.Marshal(typedres) - case crd.Function: + case fv1.Function: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "Function" data, err = yaml.Marshal(typedres) - case crd.Environment: + case fv1.Environment: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "Environment" data, err = yaml.Marshal(typedres) - case crd.HTTPTrigger: + case fv1.HTTPTrigger: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "HTTPTrigger" data, err = yaml.Marshal(typedres) - case crd.KubernetesWatchTrigger: + case fv1.KubernetesWatchTrigger: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "KubernetesWatchTrigger" data, err = yaml.Marshal(typedres) - case crd.MessageQueueTrigger: + case fv1.MessageQueueTrigger: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "MessageQueueTrigger" data, err = yaml.Marshal(typedres) - case crd.TimeTrigger: + case fv1.TimeTrigger: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "TimeTrigger" data, err = yaml.Marshal(typedres) - case crd.Recorder: + case fv1.Recorder: typedres.TypeMeta.APIVersion = SPEC_API_VERSION typedres.TypeMeta.Kind = "Recorder" data, err = yaml.Marshal(typedres) @@ -1808,7 +1808,7 @@ func (fr *FissionResources) specExists(resource interface{}, compareMetadata boo return &metav1.ObjectMeta{Name: aus.Name} } return nil - case *crd.Package: + case *fv1.Package: for _, p := range fr.packages { if compareMetadata && !reflect.DeepEqual(p.Metadata, typedres.Metadata) { continue diff --git a/fission/support/dump.go b/pkg/fission-cli/support/dump.go similarity index 96% rename from fission/support/dump.go rename to pkg/fission-cli/support/dump.go index 0e7d9320..54c535ff 100644 --- a/fission/support/dump.go +++ b/pkg/fission-cli/support/dump.go @@ -26,9 +26,9 @@ import ( "github.com/pkg/errors" "github.com/urfave/cli" - "github.com/fission/fission" - "github.com/fission/fission/fission/support/resources" - "github.com/fission/fission/fission/util" + "github.com/fission/fission/pkg/fission-cli/support/resources" + "github.com/fission/fission/pkg/fission-cli/util" + "github.com/fission/fission/pkg/utils" ) const ( @@ -127,7 +127,7 @@ func DumpInfo(c *cli.Context) error { if !nozip { defer os.Remove(dumpDir) path := filepath.Join(outputDir, fmt.Sprintf("%v.zip", dumpName)) - _, err := fission.MakeArchive(path, dumpDir) + _, err := utils.MakeArchive(path, dumpDir) if err != nil { fmt.Printf("Error creating archive for dump files: %v", err) return nil diff --git a/fission/support/resources/crd.go b/pkg/fission-cli/support/resources/crd.go similarity index 90% rename from fission/support/resources/crd.go rename to pkg/fission-cli/support/resources/crd.go index ccb8521d..e7030752 100644 --- a/fission/support/resources/crd.go +++ b/pkg/fission-cli/support/resources/crd.go @@ -21,10 +21,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/types" ) const ( @@ -112,9 +112,9 @@ func (res CrdDumper) Dump(dumpDir string) { } case CrdMessageQueueTrigger: - var triggers []crd.MessageQueueTrigger + var triggers []fv1.MessageQueueTrigger - for _, mqType := range []string{fission.MessageQueueTypeNats, fission.MessageQueueTypeASQ} { + for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} { l, err := res.client.MessageQueueTriggerList(mqType, metav1.NamespaceAll) if err != nil { log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err)) @@ -145,7 +145,7 @@ func (res CrdDumper) Dump(dumpDir string) { } } -func pkgClean(pkg crd.Package) crd.Package { +func pkgClean(pkg fv1.Package) fv1.Package { // mask the sensitive information // use "-" as mask value to indicate the field wasn't empty if pkg.Spec.Source.Literal != nil { diff --git a/fission/support/resources/fissionversion.go b/pkg/fission-cli/support/resources/fissionversion.go similarity index 90% rename from fission/support/resources/fissionversion.go rename to pkg/fission-cli/support/resources/fissionversion.go index ae58e6bb..534f7dd8 100644 --- a/fission/support/resources/fissionversion.go +++ b/pkg/fission-cli/support/resources/fissionversion.go @@ -20,8 +20,8 @@ import ( "fmt" "path/filepath" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/fission/util" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/util" ) type FissionVersion struct { diff --git a/fission/support/resources/kubernetes.go b/pkg/fission-cli/support/resources/kubernetes.go similarity index 98% rename from fission/support/resources/kubernetes.go rename to pkg/fission-cli/support/resources/kubernetes.go index f3b11172..c8c422f8 100644 --- a/fission/support/resources/kubernetes.go +++ b/pkg/fission-cli/support/resources/kubernetes.go @@ -28,8 +28,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/fission/log" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/utils" ) const ( @@ -199,7 +199,7 @@ func (res KubernetesPodLogDumper) Dump(dumpDir string) { go func(pod corev1.Pod) { defer wg.Done() - if !fission.IsReadyPod(&pod) { + if !utils.IsReadyPod(&pod) { log.Info(fmt.Sprintf("Pod %v is not in ready state, ignore it\n", pod.Name)) return } diff --git a/fission/support/resources/resource.go b/pkg/fission-cli/support/resources/resource.go similarity index 91% rename from fission/support/resources/resource.go rename to pkg/fission-cli/support/resources/resource.go index 4dc70ebc..2a56bb65 100644 --- a/fission/support/resources/resource.go +++ b/pkg/fission-cli/support/resources/resource.go @@ -24,8 +24,8 @@ import ( "github.com/ghodss/yaml" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/fission/log" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/utils" ) type Resource interface { @@ -48,7 +48,7 @@ func writeToFile(file string, obj interface{}) { // empty byte and will fail os.Create/os.Openfile with error message // "open invalid argument". To fix the problem, we need to // remove the empty byte from string. - file = string(fission.RemoveZeroBytes([]byte(file))) + file = string(utils.RemoveZeroBytes([]byte(file))) err = ioutil.WriteFile(file, bs, 0644) if err != nil { diff --git a/fission/timetrigger.go b/pkg/fission-cli/timetrigger.go similarity index 92% rename from fission/timetrigger.go rename to pkg/fission-cli/timetrigger.go index 6e31015a..3881a527 100644 --- a/fission/timetrigger.go +++ b/pkg/fission-cli/timetrigger.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -27,11 +27,10 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" ) func getAPITimeInfo(client *client.Client) time.Time { @@ -77,15 +76,15 @@ func ttCreate(c *cli.Context) error { log.Fatal("Need a cron spec like '0 30 * * * *', '@every 1h30m', or '@hourly'; use --cron") } - tt := &crd.TimeTrigger{ + tt := &fv1.TimeTrigger{ Metadata: metav1.ObjectMeta{ Name: name, Namespace: fnNamespace, }, - Spec: fission.TimeTriggerSpec{ + Spec: fv1.TimeTriggerSpec{ Cron: cronSpec, - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + FunctionReference: fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: fnName, }, }, diff --git a/fission/types.go b/pkg/fission-cli/types.go similarity index 99% rename from fission/types.go rename to pkg/fission-cli/types.go index 75974394..7740bee9 100644 --- a/fission/types.go +++ b/pkg/fission-cli/types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli const ( FISSION_DEPLOYMENT_NAME_KEY = "fission-name" diff --git a/fission/upgrade.go b/pkg/fission-cli/upgrade.go similarity index 85% rename from fission/upgrade.go rename to pkg/fission-cli/upgrade.go index dfdb5a0f..cf0ec0ff 100644 --- a/fission/upgrade.go +++ b/pkg/fission-cli/upgrade.go @@ -1,4 +1,20 @@ -package main +/* +Copyright 2016 The Fission Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fission_cli import ( "context" @@ -15,11 +31,10 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" - "github.com/fission/fission/v1" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" + v1 "github.com/fission/fission/pkg/v1" ) type ( @@ -231,9 +246,9 @@ func upgradeDumpV1State(v1url string, filename string) { len(v1state.Functions), len(v1state.HTTPTriggers), len(v1state.Watches), len(v1state.Mqtriggers), len(v1state.TimeTriggers)) } -func functionRefFromV1Metadata(m *v1.Metadata, nameRemap map[string]string) *fission.FunctionReference { - return &fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, +func functionRefFromV1Metadata(m *v1.Metadata, nameRemap map[string]string) *fv1.FunctionReference { + return &fv1.FunctionReference{ + Type: fv1.FunctionReferenceTypeFunctionName, Name: nameRemap[m.Name], } } @@ -299,14 +314,14 @@ func upgradeRestoreState(c *cli.Context) error { os.Remove(tmpfile.Name()) // create pkg - pkgSpec := fission.PackageSpec{ - Environment: fission.EnvironmentReference{ + pkgSpec := fv1.PackageSpec{ + Environment: fv1.EnvironmentReference{ Name: v1state.NameChanges[f.Environment.Name], Namespace: metav1.NamespaceDefault, }, Deployment: *archive, } - pkg, err := client.PackageCreate(&crd.Package{ + pkg, err := client.PackageCreate(&fv1.Package{ Metadata: metav1.ObjectMeta{ Name: pkgName, Namespace: metav1.NamespaceDefault, @@ -314,12 +329,12 @@ func upgradeRestoreState(c *cli.Context) error { Spec: pkgSpec, }) util.CheckErr(err, fmt.Sprintf("create package %v", pkgName)) - _, err = client.FunctionCreate(&crd.Function{ + _, err = client.FunctionCreate(&fv1.Function{ Metadata: *crdMetadataFromV1Metadata(&f.Metadata, v1state.NameChanges), - Spec: fission.FunctionSpec{ + Spec: fv1.FunctionSpec{ Environment: pkgSpec.Environment, - Package: fission.FunctionPackageRef{ - PackageRef: fission.PackageRef{ + Package: fv1.FunctionPackageRef{ + PackageRef: fv1.PackageRef{ Name: pkg.Name, Namespace: pkg.Namespace, ResourceVersion: pkg.ResourceVersion, @@ -333,11 +348,11 @@ func upgradeRestoreState(c *cli.Context) error { // create envs for _, e := range v1state.Environments { - _, err = client.EnvironmentCreate(&crd.Environment{ + _, err = client.EnvironmentCreate(&fv1.Environment{ Metadata: *crdMetadataFromV1Metadata(&e.Metadata, v1state.NameChanges), - Spec: fission.EnvironmentSpec{ + Spec: fv1.EnvironmentSpec{ Version: 1, - Runtime: fission.Runtime{ + Runtime: fv1.Runtime{ Image: e.RunContainerImageUrl, }, }, @@ -347,9 +362,9 @@ func upgradeRestoreState(c *cli.Context) error { // create httptriggers for _, t := range v1state.HTTPTriggers { - _, err = client.HTTPTriggerCreate(&crd.HTTPTrigger{ + _, err = client.HTTPTriggerCreate(&fv1.HTTPTrigger{ Metadata: *crdMetadataFromV1Metadata(&t.Metadata, v1state.NameChanges), - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ RelativeURL: t.UrlPattern, Method: t.Method, FunctionReference: *functionRefFromV1Metadata(&t.Function, v1state.NameChanges), @@ -360,11 +375,11 @@ func upgradeRestoreState(c *cli.Context) error { // create mqtriggers for _, t := range v1state.Mqtriggers { - _, err = client.MessageQueueTriggerCreate(&crd.MessageQueueTrigger{ + _, err = client.MessageQueueTriggerCreate(&fv1.MessageQueueTrigger{ Metadata: *crdMetadataFromV1Metadata(&t.Metadata, v1state.NameChanges), - Spec: fission.MessageQueueTriggerSpec{ + Spec: fv1.MessageQueueTriggerSpec{ FunctionReference: *functionRefFromV1Metadata(&t.Function, v1state.NameChanges), - MessageQueueType: fission.MessageQueueTypeNats, // only NATS is supported at that time (v1 types) + MessageQueueType: fv1.MessageQueueTypeNats, // only NATS is supported at that time (v1 types) Topic: t.Topic, ResponseTopic: t.ResponseTopic, }, @@ -374,9 +389,9 @@ func upgradeRestoreState(c *cli.Context) error { // create time triggers for _, t := range v1state.TimeTriggers { - _, err = client.TimeTriggerCreate(&crd.TimeTrigger{ + _, err = client.TimeTriggerCreate(&fv1.TimeTrigger{ Metadata: *crdMetadataFromV1Metadata(&t.Metadata, v1state.NameChanges), - Spec: fission.TimeTriggerSpec{ + Spec: fv1.TimeTriggerSpec{ FunctionReference: *functionRefFromV1Metadata(&t.Function, v1state.NameChanges), Cron: t.Cron, }, @@ -386,9 +401,9 @@ func upgradeRestoreState(c *cli.Context) error { // create watches for _, t := range v1state.Watches { - _, err = client.WatchCreate(&crd.KubernetesWatchTrigger{ + _, err = client.WatchCreate(&fv1.KubernetesWatchTrigger{ Metadata: *crdMetadataFromV1Metadata(&t.Metadata, v1state.NameChanges), - Spec: fission.KubernetesWatchTriggerSpec{ + Spec: fv1.KubernetesWatchTriggerSpec{ Namespace: t.Namespace, Type: t.ObjType, FunctionReference: *functionRefFromV1Metadata(&t.Function, v1state.NameChanges), diff --git a/fission/util/portforward.go b/pkg/fission-cli/util/portforward.go similarity index 98% rename from fission/util/portforward.go rename to pkg/fission-cli/util/portforward.go index fb3d1db6..4eff855a 100644 --- a/fission/util/portforward.go +++ b/pkg/fission-cli/util/portforward.go @@ -30,8 +30,8 @@ import ( "k8s.io/client-go/tools/portforward" "k8s.io/client-go/transport/spdy" - "github.com/fission/fission" - "github.com/fission/fission/fission/log" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/utils" ) // Port forward a free local port to a pod on the cluster. The pod is @@ -148,7 +148,7 @@ func runPortForward(labelSelector string, localPort string, ns string) error { // make sure we establish the connection to a healthy pod for _, p := range pods { - if fission.IsReadyPod(p) { + if utils.IsReadyPod(p) { podName = p.Name podNameSpace = p.Namespace break diff --git a/fission/util/util.go b/pkg/fission-cli/util/util.go similarity index 97% rename from fission/util/util.go rename to pkg/fission-cli/util/util.go index 06800f75..c2a0c9cc 100644 --- a/fission/util/util.go +++ b/pkg/fission-cli/util/util.go @@ -29,8 +29,8 @@ import ( restclient "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/fission/log" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" ) func GetApiClient(serverUrl string) *client.Client { diff --git a/fission/util/version.go b/pkg/fission-cli/util/version.go similarity index 61% rename from fission/util/version.go rename to pkg/fission-cli/util/version.go index 39ed8b63..362e3e83 100644 --- a/fission/util/version.go +++ b/pkg/fission-cli/util/version.go @@ -5,16 +5,16 @@ import ( yaml "gopkg.in/yaml.v2" - "github.com/fission/fission" - "github.com/fission/fission/controller/client" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/plugin" + "github.com/fission/fission/pkg/controller/client" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/plugin" + "github.com/fission/fission/pkg/info" ) // Versions is a container of versions of the client (and its plugins) and server (and its plugins). type Versions struct { - Client map[string]fission.BuildMeta `json:"client"` - Server map[string]fission.BuildMeta `json:"server"` + Client map[string]info.BuildMeta `json:"client"` + Server map[string]info.BuildMeta `json:"server"` } func GetVersion(client *client.Client) []byte { @@ -25,18 +25,18 @@ func GetVersion(client *client.Client) []byte { // Fetch client versions versions := Versions{ - Client: map[string]fission.BuildMeta{ - "fission/core": fission.BuildInfo(), + Client: map[string]info.BuildMeta{ + "fission/core": info.BuildInfo(), }, } for _, pmd := range plugin.FindAll() { - versions.Client[pmd.Name] = fission.BuildMeta{ + versions.Client[pmd.Name] = info.BuildMeta{ Version: pmd.Version, } } // Fetch server versions - versions.Server = map[string]fission.BuildMeta{ + versions.Server = map[string]info.BuildMeta{ "fission/core": serverInfo.Build, } // FUTURE: fetch versions of plugins server-side diff --git a/fission/watch.go b/pkg/fission-cli/watch.go similarity index 90% rename from fission/watch.go rename to pkg/fission-cli/watch.go index 53d9d240..673c98dd 100644 --- a/fission/watch.go +++ b/pkg/fission-cli/watch.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package fission_cli import ( "fmt" @@ -25,10 +25,9 @@ import ( "github.com/urfave/cli" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/fission/log" - "github.com/fission/fission/fission/util" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/fission-cli/log" + "github.com/fission/fission/pkg/fission-cli/util" ) func wCreate(c *cli.Context) error { @@ -64,18 +63,18 @@ func wCreate(c *cli.Context) error { // automatically name watches watchName := uuid.NewV4().String() - w := &crd.KubernetesWatchTrigger{ + w := &fv1.KubernetesWatchTrigger{ Metadata: metav1.ObjectMeta{ Name: watchName, Namespace: fnNamespace, }, - Spec: fission.KubernetesWatchTriggerSpec{ + Spec: fv1.KubernetesWatchTriggerSpec{ Namespace: namespace, Type: objType, //LabelSelector: labels, - FunctionReference: fission.FunctionReference{ + FunctionReference: fv1.FunctionReference{ Name: fnName, - Type: fission.FunctionReferenceTypeFunctionName, + Type: fv1.FunctionReferenceTypeFunctionName, }, }, } diff --git a/pkg/fission/fission b/pkg/fission/fission new file mode 100755 index 00000000..e8b3c0d1 Binary files /dev/null and b/pkg/fission/fission differ diff --git a/info.go b/pkg/info/info.go similarity index 99% rename from info.go rename to pkg/info/info.go index b4271105..44be3685 100644 --- a/info.go +++ b/pkg/info/info.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fission +package info import ( "encoding/json" diff --git a/kubewatcher/kubewatcher.go b/pkg/kubewatcher/kubewatcher.go similarity index 89% rename from kubewatcher/kubewatcher.go rename to pkg/kubewatcher/kubewatcher.go index 2f65c207..28371b77 100644 --- a/kubewatcher/kubewatcher.go +++ b/pkg/kubewatcher/kubewatcher.go @@ -35,9 +35,10 @@ import ( "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/kubernetes" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/publisher" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + ferror "github.com/fission/fission/pkg/error" + "github.com/fission/fission/pkg/publisher" + "github.com/fission/fission/pkg/utils" ) type requestType int @@ -58,7 +59,7 @@ type ( watchSubscription struct { logger *zap.Logger - watch crd.KubernetesWatchTrigger + watch fv1.KubernetesWatchTrigger kubeWatch watch.Interface lastResourceVersion string stopped *int32 @@ -68,7 +69,7 @@ type ( kubeWatcherRequest struct { requestType - watches []crd.KubernetesWatchTrigger + watches []fv1.KubernetesWatchTrigger responseChannel chan *kubeWatcherResponse } kubeWatcherResponse struct { @@ -88,7 +89,7 @@ func MakeKubeWatcher(logger *zap.Logger, kubernetesClient *kubernetes.Clientset, return kw } -func (kw *KubeWatcher) Sync(watches []crd.KubernetesWatchTrigger) error { +func (kw *KubeWatcher) Sync(watches []fv1.KubernetesWatchTrigger) error { req := &kubeWatcherRequest{ requestType: SYNC, watches: watches, @@ -148,7 +149,7 @@ func printKubernetesObject(obj runtime.Object, w io.Writer) error { return err } -func createKubernetesWatch(kubeClient *kubernetes.Clientset, w *crd.KubernetesWatchTrigger, resourceVersion string) (watch.Interface, error) { +func createKubernetesWatch(kubeClient *kubernetes.Clientset, w *fv1.KubernetesWatchTrigger, resourceVersion string) (watch.Interface, error) { var wi watch.Interface var err error var watchTimeoutSec int64 = 120 @@ -175,7 +176,7 @@ func createKubernetesWatch(kubeClient *kubernetes.Clientset, w *crd.KubernetesWa return wi, err } -func (kw *KubeWatcher) addWatch(w *crd.KubernetesWatchTrigger) error { +func (kw *KubeWatcher) addWatch(w *fv1.KubernetesWatchTrigger) error { kw.logger.Info("adding watch", zap.String("name", w.Metadata.Name), zap.Any("function", w.Spec.FunctionReference)) ws, err := MakeWatchSubscription(kw.logger.Named("watchsubscription"), w, kw.kubernetesClient, kw.publisher) if err != nil { @@ -185,11 +186,11 @@ func (kw *KubeWatcher) addWatch(w *crd.KubernetesWatchTrigger) error { return nil } -func (kw *KubeWatcher) removeWatch(w *crd.KubernetesWatchTrigger) error { +func (kw *KubeWatcher) removeWatch(w *fv1.KubernetesWatchTrigger) error { kw.logger.Info("removing watch", zap.String("name", w.Metadata.Name), zap.Any("function", w.Spec.FunctionReference)) ws, ok := kw.watches[w.Metadata.UID] if !ok { - return fission.MakeError(fission.ErrorNotFound, + return ferror.MakeError(ferror.ErrorNotFound, fmt.Sprintf("watch doesn't exist: %v", w.Metadata)) } delete(kw.watches, w.Metadata.UID) @@ -197,22 +198,7 @@ func (kw *KubeWatcher) removeWatch(w *crd.KubernetesWatchTrigger) error { return nil } -// wi, err := kw.createKubernetesWatch(w) -// if err != nil { -// return err -// } -// var stopped int32 = 0 -// ws := &watchSubscription{ -// Watch: *w, -// kubeWatch: wi, -// stopped: &stopped, -// } -// kw.watches[w.Metadata.Uid] = *ws -// go ws.eventDispatchLoop(kw.publisher) -// return nil -// } - -func MakeWatchSubscription(logger *zap.Logger, w *crd.KubernetesWatchTrigger, kubeClient *kubernetes.Clientset, publisher publisher.Publisher) (*watchSubscription, error) { +func MakeWatchSubscription(logger *zap.Logger, w *fv1.KubernetesWatchTrigger, kubeClient *kubernetes.Clientset, publisher publisher.Publisher) (*watchSubscription, error) { var stopped int32 = 0 ws := &watchSubscription{ logger: logger.Named("watch_subscription"), @@ -326,7 +312,7 @@ func (ws *watchSubscription) eventDispatchLoop() { } // TODO support other function ref types. Or perhaps delegate to router? - if ws.watch.Spec.FunctionReference.Type != fission.FunctionReferenceTypeFunctionName { + if ws.watch.Spec.FunctionReference.Type != fv1.FunctionReferenceTypeFunctionName { ws.logger.Error("unsupported function ref type - cannot publish event", zap.Any("type", ws.watch.Spec.FunctionReference.Type), zap.String("watch_name", ws.watch.Metadata.Name)) @@ -336,7 +322,7 @@ func (ws *watchSubscription) eventDispatchLoop() { // with the addition of multi-tenancy, the users can create functions in any namespace. however, // the triggers can only be created in the same namespace as the function. // so essentially, function namespace = trigger namespace. - url := fission.UrlForFunction(ws.watch.Spec.FunctionReference.Name, ws.watch.Metadata.Namespace) + url := utils.UrlForFunction(ws.watch.Spec.FunctionReference.Name, ws.watch.Metadata.Namespace) ws.publisher.Publish(buf.String(), headers, url) } } diff --git a/kubewatcher/main.go b/pkg/kubewatcher/main.go similarity index 93% rename from kubewatcher/main.go rename to pkg/kubewatcher/main.go index ebca054f..f022894c 100644 --- a/kubewatcher/main.go +++ b/pkg/kubewatcher/main.go @@ -20,8 +20,8 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission/crd" - "github.com/fission/fission/publisher" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/publisher" ) func Start(logger *zap.Logger, routerUrl string) error { diff --git a/kubewatcher/watchSync.go b/pkg/kubewatcher/watchSync.go similarity index 97% rename from kubewatcher/watchSync.go rename to pkg/kubewatcher/watchSync.go index 9f0f4ba7..6d8c8f89 100644 --- a/kubewatcher/watchSync.go +++ b/pkg/kubewatcher/watchSync.go @@ -22,7 +22,7 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" ) type ( diff --git a/logger/influxdb/Dockerfile b/pkg/logger/influxdb/Dockerfile similarity index 100% rename from logger/influxdb/Dockerfile rename to pkg/logger/influxdb/Dockerfile diff --git a/logger/influxdb/README.md b/pkg/logger/influxdb/README.md similarity index 100% rename from logger/influxdb/README.md rename to pkg/logger/influxdb/README.md diff --git a/logger/influxdb/config.toml b/pkg/logger/influxdb/config.toml similarity index 100% rename from logger/influxdb/config.toml rename to pkg/logger/influxdb/config.toml diff --git a/logger/influxdb/run.sh b/pkg/logger/influxdb/run.sh similarity index 100% rename from logger/influxdb/run.sh rename to pkg/logger/influxdb/run.sh diff --git a/logger/influxdb/types.db b/pkg/logger/influxdb/types.db similarity index 100% rename from logger/influxdb/types.db rename to pkg/logger/influxdb/types.db diff --git a/logger/logger.go b/pkg/logger/logger.go similarity index 91% rename from logger/logger.go rename to pkg/logger/logger.go index c06a85ce..9687d9a9 100644 --- a/logger/logger.go +++ b/pkg/logger/logger.go @@ -23,6 +23,8 @@ import ( "strings" "time" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" log "github.com/sirupsen/logrus" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" @@ -31,8 +33,7 @@ import ( "k8s.io/client-go/kubernetes" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" ) var nodeName = os.Getenv("NODE_NAME") @@ -49,24 +50,24 @@ func makePodLoggerController(zapLogger *zap.Logger, k8sClientSet *kubernetes.Cli k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { pod := obj.(*corev1.Pod) - if !isValidFunctionPodOnNode(pod) || !fission.IsReadyPod(pod) { + if !isValidFunctionPodOnNode(pod) || !utils.IsReadyPod(pod) { return } err := createLogSymlinks(zapLogger, pod) if err != nil { - funcName := pod.Labels[fission.FUNCTION_NAME] + funcName := pod.Labels[types.FUNCTION_NAME] zapLogger.Error("error creating symlink", zap.String("function", funcName), zap.Error(err)) } }, UpdateFunc: func(_, obj interface{}) { pod := obj.(*corev1.Pod) - if !isValidFunctionPodOnNode(pod) || !fission.IsReadyPod(pod) { + if !isValidFunctionPodOnNode(pod) || !utils.IsReadyPod(pod) { return } err := createLogSymlinks(zapLogger, pod) if err != nil { - funcName := pod.Labels[fission.FUNCTION_NAME] + funcName := pod.Labels[types.FUNCTION_NAME] zapLogger.Error("error creating symlink", zap.String("function", funcName), zap.Error(err)) } @@ -114,8 +115,8 @@ func isValidFunctionPodOnNode(pod *corev1.Pod) bool { if pod.Spec.NodeName != nodeName { return false } - labels := []string{fission.ENVIRONMENT_NAMESPACE, fission.ENVIRONMENT_NAME, fission.ENVIRONMENT_UID, - fission.FUNCTION_NAMESPACE, fission.FUNCTION_NAME, fission.FUNCTION_UID, fission.EXECUTOR_TYPE} + labels := []string{types.ENVIRONMENT_NAMESPACE, types.ENVIRONMENT_NAME, types.ENVIRONMENT_UID, + types.FUNCTION_NAMESPACE, types.FUNCTION_NAME, types.FUNCTION_UID, types.EXECUTOR_TYPE} for _, l := range labels { if len(pod.Labels[l]) == 0 { return false diff --git a/mqtrigger/messageQueue/asq.go b/pkg/mqtrigger/messageQueue/asq.go similarity index 96% rename from mqtrigger/messageQueue/asq.go rename to pkg/mqtrigger/messageQueue/asq.go index 1a574a62..19bf4d1d 100644 --- a/mqtrigger/messageQueue/asq.go +++ b/pkg/mqtrigger/messageQueue/asq.go @@ -29,11 +29,12 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/storage" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) // TODO: some of these constants should probably be environment variables @@ -200,10 +201,10 @@ func newAzureStorageConnection(logger *zap.Logger, routerURL string, config Mess }, nil } -func (asc AzureStorageConnection) subscribe(trigger *crd.MessageQueueTrigger) (messageQueueSubscription, error) { +func (asc AzureStorageConnection) subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) { asc.logger.Info("subscribing to Azure storage queue", zap.String("queue", trigger.Spec.Topic)) - if trigger.Spec.FunctionReference.Type != fission.FunctionReferenceTypeFunctionName { + if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { return nil, fmt.Errorf("unsupported function reference type (%v) for trigger %q", trigger.Spec.FunctionReference.Type, trigger.Metadata.Name) } @@ -214,7 +215,7 @@ func (asc AzureStorageConnection) subscribe(trigger *crd.MessageQueueTrigger) (m // with the addition of multi-tenancy, the users can create functions in any namespace. however, // the triggers can only be created in the same namespace as the function. // so essentially, function namespace = trigger namespace. - functionURL: asc.routerURL + "/" + strings.TrimPrefix(fission.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/"), + functionURL: asc.routerURL + "/" + strings.TrimPrefix(utils.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/"), contentType: trigger.Spec.ContentType, unsubscribe: make(chan bool), done: make(chan bool), diff --git a/mqtrigger/messageQueue/asq_test.go b/pkg/mqtrigger/messageQueue/asq_test.go similarity index 95% rename from mqtrigger/messageQueue/asq_test.go rename to pkg/mqtrigger/messageQueue/asq_test.go index 655fc80d..a12d2555 100644 --- a/mqtrigger/messageQueue/asq_test.go +++ b/pkg/mqtrigger/messageQueue/asq_test.go @@ -26,13 +26,13 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/storage" + "github.com/fission/fission/pkg/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) const ( @@ -114,7 +114,7 @@ func TestNewStorageConnectionMissingAccountName(t *testing.T) { panicIf(err) connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{ - MQType: fission.MessageQueueTypeASQ, + MQType: types.MessageQueueTypeASQ, Url: "", }) require.Nil(t, connection) @@ -127,7 +127,7 @@ func TestNewStorageConnectionMissingAccessKey(t *testing.T) { _ = os.Setenv("AZURE_STORAGE_ACCOUNT_NAME", "accountname") connection, err := newAzureStorageConnection(logger, DummyRouterURL, MessageQueueConfig{ - MQType: fission.MessageQueueTypeASQ, + MQType: types.MessageQueueTypeASQ, Url: "", }) _ = os.Unsetenv("AZURE_STORAGE_ACCOUNT_NAME") @@ -302,17 +302,17 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) { service: service, httpClient: httpClient, } - subscription, err := connection.subscribe(&crd.MessageQueueTrigger{ + subscription, err := connection.subscribe(&fv1.MessageQueueTrigger{ Metadata: metav1.ObjectMeta{ Name: TriggerName, Namespace: metav1.NamespaceDefault, }, - Spec: fission.MessageQueueTriggerSpec{ - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + Spec: fv1.MessageQueueTriggerSpec{ + FunctionReference: fv1.FunctionReference{ + Type: types.FunctionReferenceTypeFunctionName, Name: FunctionName, }, - MessageQueueType: fission.MessageQueueTypeASQ, + MessageQueueType: types.MessageQueueTypeASQ, Topic: QueueName, ContentType: ContentType, }, @@ -450,17 +450,17 @@ func runAzureStorageQueueTest(t *testing.T, count int, output bool) { service: service, httpClient: httpClient, } - subscription, err := connection.subscribe(&crd.MessageQueueTrigger{ + subscription, err := connection.subscribe(&fv1.MessageQueueTrigger{ Metadata: metav1.ObjectMeta{ Name: TriggerName, Namespace: metav1.NamespaceDefault, }, - Spec: fission.MessageQueueTriggerSpec{ - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + Spec: fv1.MessageQueueTriggerSpec{ + FunctionReference: fv1.FunctionReference{ + Type: types.FunctionReferenceTypeFunctionName, Name: FunctionName, }, - MessageQueueType: fission.MessageQueueTypeASQ, + MessageQueueType: types.MessageQueueTypeASQ, Topic: QueueName, ResponseTopic: responseTopic, ContentType: ContentType, diff --git a/mqtrigger/messageQueue/kafka.go b/pkg/mqtrigger/messageQueue/kafka.go similarity index 93% rename from mqtrigger/messageQueue/kafka.go rename to pkg/mqtrigger/messageQueue/kafka.go index cc8012e8..0cfc7dbd 100644 --- a/mqtrigger/messageQueue/kafka.go +++ b/pkg/mqtrigger/messageQueue/kafka.go @@ -26,10 +26,11 @@ import ( sarama "github.com/Shopify/sarama" cluster "github.com/bsm/sarama-cluster" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type ( @@ -70,7 +71,7 @@ func isTopicValidForKafka(topic string) bool { return true } -func (kafka Kafka) subscribe(trigger *crd.MessageQueueTrigger) (messageQueueSubscription, error) { +func (kafka Kafka) subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) { kafka.logger.Info("inside kakfa subscribe", zap.Any("trigger", trigger)) kafka.logger.Info("brokers set", zap.Strings("brokers", kafka.brokers)) @@ -128,16 +129,16 @@ func (kafka Kafka) unsubscribe(subscription messageQueueSubscription) error { return subscription.(*cluster.Consumer).Close() } -func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *crd.MessageQueueTrigger, msg *sarama.ConsumerMessage) bool { +func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *fv1.MessageQueueTrigger, msg *sarama.ConsumerMessage) bool { var value string = string(msg.Value[:]) // Support other function ref types - if trigger.Spec.FunctionReference.Type != fission.FunctionReferenceTypeFunctionName { + if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { kafka.logger.Fatal("unsupported function reference type for trigger", zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type), zap.String("trigger", trigger.Metadata.Name)) } - url := kafka.routerUrl + "/" + strings.TrimPrefix(fission.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/") + url := kafka.routerUrl + "/" + strings.TrimPrefix(utils.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/") kafka.logger.Info("making HTTP request", zap.String("url", url)) // Generate the Headers @@ -244,7 +245,7 @@ func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *crd.Me return true } -func errorHandler(logger *zap.Logger, trigger *crd.MessageQueueTrigger, producer sarama.SyncProducer, body string) { +func errorHandler(logger *zap.Logger, trigger *fv1.MessageQueueTrigger, producer sarama.SyncProducer, body string) { if len(trigger.Spec.ErrorTopic) > 0 { _, _, err := producer.SendMessage(&sarama.ProducerMessage{ Topic: trigger.Spec.ErrorTopic, diff --git a/mqtrigger/messageQueue/messageQueue.go b/pkg/mqtrigger/messageQueue/messageQueue.go similarity index 93% rename from mqtrigger/messageQueue/messageQueue.go rename to pkg/mqtrigger/messageQueue/messageQueue.go index f0d43ea3..8afe4dd1 100644 --- a/mqtrigger/messageQueue/messageQueue.go +++ b/pkg/mqtrigger/messageQueue/messageQueue.go @@ -21,12 +21,13 @@ import ( "fmt" "time" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" ) const ( @@ -46,7 +47,7 @@ type ( } MessageQueue interface { - subscribe(trigger *crd.MessageQueueTrigger) (messageQueueSubscription, error) + subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) unsubscribe(triggerSub messageQueueSubscription) error } @@ -60,7 +61,7 @@ type ( } triggerSubscription struct { - trigger crd.MessageQueueTrigger + trigger fv1.MessageQueueTrigger subscription messageQueueSubscription } @@ -86,11 +87,11 @@ func MakeMessageQueueTriggerManager(logger *zap.Logger, fissionClient *crd.Fissi fissionClient: fissionClient, } switch mqConfig.MQType { - case fission.MessageQueueTypeNats: + case types.MessageQueueTypeNats: messageQueue, err = makeNatsMessageQueue(logger, routerUrl, mqConfig) - case fission.MessageQueueTypeASQ: + case types.MessageQueueTypeASQ: messageQueue, err = newAzureStorageConnection(logger, routerUrl, mqConfig) - case fission.MessageQueueTypeKafka: + case types.MessageQueueTypeKafka: messageQueue, err = makeKafkaMessageQueue(logger, routerUrl, mqConfig) default: err = fmt.Errorf("no supported message queue type found for %q", mqConfig.MQType) @@ -154,7 +155,7 @@ func (mqt *MessageQueueTriggerManager) delTrigger(m *metav1.ObjectMeta) { mqt.reqChan <- request{ requestType: DELETE_TRIGGER, triggerSub: &triggerSubscription{ - trigger: crd.MessageQueueTrigger{ + trigger: fv1.MessageQueueTrigger{ Metadata: *m, }, }, @@ -166,14 +167,14 @@ func (mqt *MessageQueueTriggerManager) syncTriggers() { // get new set of triggers newTriggers, err := mqt.fissionClient.MessageQueueTriggers(metav1.NamespaceAll).List(metav1.ListOptions{}) if err != nil { - if fission.IsNetworkError(err) { + if utils.IsNetworkError(err) { mqt.logger.Info("encountered network error, will retry", zap.Error(err)) time.Sleep(5 * time.Second) continue } mqt.logger.Fatal("failed to read message queue trigger list", zap.Error(err)) } - newTriggerMap := make(map[string]*crd.MessageQueueTrigger) + newTriggerMap := make(map[string]*fv1.MessageQueueTrigger) for index := range newTriggers.Items { newTrigger := &newTriggers.Items[index] newTriggerMap[crd.CacheKey(&newTrigger.Metadata)] = newTrigger diff --git a/mqtrigger/messageQueue/nats.go b/pkg/mqtrigger/messageQueue/nats.go similarity index 92% rename from mqtrigger/messageQueue/nats.go rename to pkg/mqtrigger/messageQueue/nats.go index 4b8a6ec7..7676daea 100644 --- a/mqtrigger/messageQueue/nats.go +++ b/pkg/mqtrigger/messageQueue/nats.go @@ -27,8 +27,9 @@ import ( nsUtil "github.com/nats-io/nats-streaming-server/util" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" ) const ( @@ -68,7 +69,7 @@ func makeNatsMessageQueue(logger *zap.Logger, routerUrl string, mqCfg MessageQue return nats, nil } -func (nats Nats) subscribe(trigger *crd.MessageQueueTrigger) (messageQueueSubscription, error) { +func (nats Nats) subscribe(trigger *fv1.MessageQueueTrigger) (messageQueueSubscription, error) { subj := trigger.Spec.Topic if !isTopicValidForNats(subj) { @@ -101,11 +102,11 @@ func isTopicValidForNats(topic string) bool { return nsUtil.IsChannelNameValid(topic, false) } -func msgHandler(nats *Nats, trigger *crd.MessageQueueTrigger) func(*ns.Msg) { +func msgHandler(nats *Nats, trigger *fv1.MessageQueueTrigger) func(*ns.Msg) { return func(msg *ns.Msg) { // Support other function ref types - if trigger.Spec.FunctionReference.Type != fission.FunctionReferenceTypeFunctionName { + if trigger.Spec.FunctionReference.Type != types.FunctionReferenceTypeFunctionName { nats.logger.Fatal("unsupported function reference type for trigger", zap.Any("function_reference_type", trigger.Spec.FunctionReference.Type), zap.String("trigger", trigger.Metadata.Name)) @@ -114,7 +115,7 @@ func msgHandler(nats *Nats, trigger *crd.MessageQueueTrigger) func(*ns.Msg) { // with the addition of multi-tenancy, the users can create functions in any namespace. however, // the triggers can only be created in the same namespace as the function. // so essentially, function namespace = trigger namespace. - url := nats.routerUrl + "/" + strings.TrimPrefix(fission.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/") + url := nats.routerUrl + "/" + strings.TrimPrefix(utils.UrlForFunction(trigger.Spec.FunctionReference.Name, trigger.Metadata.Namespace), "/") nats.logger.Info("making HTTP request", zap.String("url", url)) headers := map[string]string{ diff --git a/mqtrigger/main.go b/pkg/mqtrigger/mqtrigger.go similarity index 91% rename from mqtrigger/main.go rename to pkg/mqtrigger/mqtrigger.go index cc8f75d1..dba5faa7 100644 --- a/mqtrigger/main.go +++ b/pkg/mqtrigger/mqtrigger.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package messagequeue +package mqtrigger import ( "os" @@ -22,8 +22,8 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission/crd" - "github.com/fission/fission/mqtrigger/messageQueue" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/mqtrigger/messageQueue" ) func Start(logger *zap.Logger, routerUrl string) error { diff --git a/publisher/publisher.go b/pkg/publisher/publisher.go similarity index 100% rename from publisher/publisher.go rename to pkg/publisher/publisher.go diff --git a/publisher/webhookPublisher.go b/pkg/publisher/webhookPublisher.go similarity index 100% rename from publisher/webhookPublisher.go rename to pkg/publisher/webhookPublisher.go diff --git a/redis/README.md b/pkg/redis/README.md similarity index 100% rename from redis/README.md rename to pkg/redis/README.md diff --git a/redis/build/gen/spec.pb.go b/pkg/redis/build/gen/spec.pb.go similarity index 100% rename from redis/build/gen/spec.pb.go rename to pkg/redis/build/gen/spec.pb.go diff --git a/redis/redis.go b/pkg/redis/redis.go similarity index 98% rename from redis/redis.go rename to pkg/redis/redis.go index 79d5e15b..e58f60d5 100644 --- a/redis/redis.go +++ b/pkg/redis/redis.go @@ -29,7 +29,7 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission/redis/build/gen" + "github.com/fission/fission/pkg/redis/build/gen" ) func NewClient() (redis.Conn, error) { diff --git a/redis/redisApi.go b/pkg/redis/redisApi.go similarity index 97% rename from redis/redisApi.go rename to pkg/redis/redisApi.go index 7b16cad6..a3a4c5bf 100644 --- a/redis/redisApi.go +++ b/pkg/redis/redisApi.go @@ -32,8 +32,8 @@ import ( "github.com/gomodule/redigo/redis" "github.com/pkg/errors" - "github.com/fission/fission/crd" - "github.com/fission/fission/redis/build/gen" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/redis/build/gen" ) func RecordsListAll(logger *zap.Logger) ([]byte, error) { @@ -156,7 +156,7 @@ func RecordsFilterByTime(logger *zap.Logger, from string, to string) ([]byte, er return resp, nil } -func RecordsFilterByTrigger(logger *zap.Logger, queriedTriggerName string, recorders *crd.RecorderList, triggers *crd.HTTPTriggerList) ([]byte, error) { +func RecordsFilterByTrigger(logger *zap.Logger, queriedTriggerName string, recorders *fv1.RecorderList, triggers *fv1.HTTPTriggerList) ([]byte, error) { matchingRecorders := make(map[string]bool) // Implicit triggers: @@ -227,14 +227,14 @@ func RecordsFilterByTrigger(logger *zap.Logger, queriedTriggerName string, recor return resp, nil } -func RecordsFilterByFunction(logger *zap.Logger, queriedFunctionName string, recorders *crd.RecorderList, triggers *crd.HTTPTriggerList) ([]byte, error) { +func RecordsFilterByFunction(logger *zap.Logger, queriedFunctionName string, recorders *fv1.RecorderList, triggers *fv1.HTTPTriggerList) ([]byte, error) { // Implicit functions: // Sometimes functions are not explicitly attached to recorders but we still want to be able to // filter records by those functions; we do so by identifying all triggers recorders are associated with // and checking functionReferences for those triggers. - triggerMap := make(map[string]crd.HTTPTrigger) + triggerMap := make(map[string]fv1.HTTPTrigger) for _, trigger := range triggers.Items { triggerMap[trigger.Metadata.Name] = trigger } diff --git a/redis/spec.proto b/pkg/redis/spec.proto similarity index 100% rename from redis/spec.proto rename to pkg/redis/spec.proto diff --git a/router/analytics.go b/pkg/router/analytics.go similarity index 100% rename from router/analytics.go rename to pkg/router/analytics.go diff --git a/router/functionHandler.go b/pkg/router/functionHandler.go similarity index 96% rename from router/functionHandler.go rename to pkg/router/functionHandler.go index 10d574da..96be0414 100644 --- a/router/functionHandler.go +++ b/pkg/router/functionHandler.go @@ -30,6 +30,8 @@ import ( "strings" "time" + "github.com/fission/fission/pkg/types" + "github.com/fission/fission/pkg/utils" "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/satori/go.uuid" @@ -37,11 +39,12 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - executorClient "github.com/fission/fission/executor/client" - "github.com/fission/fission/redis" - "github.com/fission/fission/throttler" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + ferror "github.com/fission/fission/pkg/error" + executorClient "github.com/fission/fission/pkg/executor/client" + "github.com/fission/fission/pkg/redis" + "github.com/fission/fission/pkg/throttler" ) const ( @@ -57,7 +60,7 @@ type ( trmap *triggerRecorderMap executor *executorClient.Client function *metav1.ObjectMeta - httpTrigger *crd.HTTPTrigger + httpTrigger *fv1.HTTPTrigger functionMetadataMap map[string]*metav1.ObjectMeta fnWeightDistributionList []FunctionWeightDistribution tsRoundTripperParams *tsRoundTripperParams @@ -222,7 +225,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (resp *htt if err != nil { // We might want a specific error code or header for fission failures as opposed to // user function bugs. - statusCode, errMsg := fission.GetHTTPError(err) + statusCode, errMsg := ferror.GetHTTPError(err) if roundTripper.funcHandler.isDebugEnv { return &http.Response{ StatusCode: statusCode, @@ -235,7 +238,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (resp *htt Header: make(http.Header, 0), }, nil } - return nil, fission.MakeError(http.StatusInternalServerError, err.Error()) + return nil, ferror.MakeError(http.StatusInternalServerError, err.Error()) } // service url maybe nil if router cannot find one in cache, @@ -306,7 +309,7 @@ func (roundTripper RetryingRoundTripper) RoundTrip(req *http.Request) (resp *htt } // if transport.RoundTrip returns a non-network dial error, then relay it back to user - if !fission.IsNetworkDialError(err) { + if !utils.IsNetworkDialError(err) { err = errors.Wrapf(err, "error sending request to function %v", fnMeta.Name) return resp, err } @@ -395,7 +398,7 @@ func (fh functionHandler) handler(responseWriter http.ResponseWriter, request *h fh.logger.Info("record request", zap.String("request_id", reqUID)) } - if fh.httpTrigger != nil && fh.httpTrigger.Spec.FunctionReference.Type == fission.FunctionReferenceTypeFunctionWeights { + if fh.httpTrigger != nil && fh.httpTrigger.Spec.FunctionReference.Type == types.FunctionReferenceTypeFunctionWeights { // canary deployment. need to determine the function to send request to now fnMetadata := getCanaryBackend(fh.functionMetadataMap, fh.fnWeightDistributionList) if fnMetadata == nil { @@ -592,18 +595,18 @@ func (fh *functionHandler) getServiceEntryFromCache() (serviceUrl *url.URL, err if err != nil { var errMsg string - e, ok := err.(fission.Error) + e, ok := err.(ferror.Error) if !ok { errMsg = fmt.Sprintf("Unknown error when looking up service entry: %v", err) } else { // Ignore ErrorNotFound error here, it's an expected error, // roundTripper will try to get service url later. - if e.Code == fission.ErrorNotFound { + if e.Code == ferror.ErrorNotFound { return nil, nil } errMsg = fmt.Sprintf("Error getting function %v;s service entry from cache: %v", fh.function.Name, err) } - return nil, fission.MakeError(http.StatusInternalServerError, errMsg) + return nil, ferror.MakeError(http.StatusInternalServerError, errMsg) } return serviceUrl, nil } @@ -613,7 +616,7 @@ func (fh *functionHandler) getServiceEntryFromExecutor(ctx context.Context) (*ur // send a request to executor to specialize a new pod service, err := fh.executor.GetServiceForFunction(ctx, fh.function) if err != nil { - statusCode, errMsg := fission.GetHTTPError(err) + statusCode, errMsg := ferror.GetHTTPError(err) fh.logger.Error("error from GetServiceForFunction", zap.Error(err), zap.String("error_message", errMsg), diff --git a/router/functionHandler_test.go b/pkg/router/functionHandler_test.go similarity index 89% rename from router/functionHandler_test.go rename to pkg/router/functionHandler_test.go index d1887c0a..c04353d1 100644 --- a/router/functionHandler_test.go +++ b/pkg/router/functionHandler_test.go @@ -27,8 +27,8 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/types" ) func createBackendService(testResponseString string) *url.URL { @@ -61,15 +61,15 @@ func TestFunctionProxying(t *testing.T) { fmap := makeFunctionServiceMap(logger, 0) fmap.assign(fn, backendURL) - httpTrigger := &crd.HTTPTrigger{ + httpTrigger := &fv1.HTTPTrigger{ Metadata: metav1.ObjectMeta{ Name: "xxx", Namespace: metav1.NamespaceDefault, ResourceVersion: "1234", }, - Spec: fission.HTTPTriggerSpec{ - FunctionReference: fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + Spec: fv1.HTTPTriggerSpec{ + FunctionReference: fv1.FunctionReference{ + Type: types.FunctionReferenceTypeFunctionName, }, }, } diff --git a/router/functionRecorderMap.go b/pkg/router/functionRecorderMap.go similarity index 78% rename from router/functionRecorderMap.go rename to pkg/router/functionRecorderMap.go index 144b2281..a20a2a08 100644 --- a/router/functionRecorderMap.go +++ b/pkg/router/functionRecorderMap.go @@ -21,15 +21,15 @@ import ( "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" + ferror "github.com/fission/fission/pkg/error" ) type ( functionRecorderMap struct { logger *zap.Logger - cache *cache.Cache // map[string]*crd.Recorder + cache *cache.Cache // map[string]*fv1.Recorder } ) @@ -41,19 +41,19 @@ func makeFunctionRecorderMap(logger *zap.Logger, expiry time.Duration) *function } } -func (frmap *functionRecorderMap) lookup(function string) (*crd.Recorder, error) { +func (frmap *functionRecorderMap) lookup(function string) (*fv1.Recorder, error) { item, err := frmap.cache.Get(function) if err != nil { return nil, err } - u := item.(*crd.Recorder) + u := item.(*fv1.Recorder) return u, nil } -func (frmap *functionRecorderMap) assign(function string, recorder *crd.Recorder) { +func (frmap *functionRecorderMap) assign(function string, recorder *fv1.Recorder) { err, _ := frmap.cache.Set(function, recorder) if err != nil { - if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNameExists { + if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists { return } frmap.logger.Error("error caching recorder for function name with a different value", zap.Error(err)) diff --git a/router/functionReferenceResolver.go b/pkg/router/functionReferenceResolver.go similarity index 91% rename from router/functionReferenceResolver.go rename to pkg/router/functionReferenceResolver.go index 3e18a3b5..0f5c970f 100644 --- a/router/functionReferenceResolver.go +++ b/pkg/router/functionReferenceResolver.go @@ -27,9 +27,8 @@ import ( "k8s.io/client-go/rest" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" ) type ( @@ -93,12 +92,12 @@ func makeK8SCache(crdClient *rest.RESTClient) (k8sCache.Store, k8sCache.Controll }, } resyncPeriod := 30 * time.Second - return k8sCache.NewInformer(listWatch, &crd.Function{}, resyncPeriod, + return k8sCache.NewInformer(listWatch, &fv1.Function{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{}) } // resolve translates a trigger's function reference to a resolveResult. -func (frr *functionReferenceResolver) resolve(trigger crd.HTTPTrigger) (*resolveResult, error) { +func (frr *functionReferenceResolver) resolve(trigger fv1.HTTPTrigger) (*resolveResult, error) { nfr := namespacedTriggerReference{ namespace: trigger.Metadata.Namespace, triggerName: trigger.Metadata.Name, @@ -116,13 +115,13 @@ func (frr *functionReferenceResolver) resolve(trigger crd.HTTPTrigger) (*resolve var rr *resolveResult switch trigger.Spec.FunctionReference.Type { - case fission.FunctionReferenceTypeFunctionName: + case fv1.FunctionReferenceTypeFunctionName: rr, err = frr.resolveByName(nfr.namespace, trigger.Spec.FunctionReference.Name) if err != nil { return nil, err } - case fission.FunctionReferenceTypeFunctionWeights: + case fv1.FunctionReferenceTypeFunctionWeights: rr, err = frr.resolveByFunctionWeights(nfr.namespace, &trigger.Spec.FunctionReference) if err != nil { return nil, err @@ -141,7 +140,7 @@ func (frr *functionReferenceResolver) resolve(trigger crd.HTTPTrigger) (*resolve // resolveByName simply looks up function by name in a namespace. func (frr *functionReferenceResolver) resolveByName(namespace, name string) (*resolveResult, error) { // get function from cache - obj, isExist, err := frr.store.Get(&crd.Function{ + obj, isExist, err := frr.store.Get(&fv1.Function{ Metadata: metav1.ObjectMeta{ Namespace: namespace, Name: name, @@ -154,7 +153,7 @@ func (frr *functionReferenceResolver) resolveByName(namespace, name string) (*re return nil, fmt.Errorf("function %v does not exist", name) } - f := obj.(*crd.Function) + f := obj.(*fv1.Function) functionMetadataMap := make(map[string]*metav1.ObjectMeta, 1) functionMetadataMap[f.Metadata.Name] = &f.Metadata @@ -166,7 +165,7 @@ func (frr *functionReferenceResolver) resolveByName(namespace, name string) (*re return &rr, nil } -func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, fr *fission.FunctionReference) (*resolveResult, error) { +func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, fr *fv1.FunctionReference) (*resolveResult, error) { functionMetadataMap := make(map[string]*metav1.ObjectMeta, 0) fnWtDistrList := make([]FunctionWeightDistribution, 0) @@ -174,7 +173,7 @@ func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, for functionName, functionWeight := range fr.FunctionWeights { // get function from cache - obj, isExist, err := frr.store.Get(&crd.Function{ + obj, isExist, err := frr.store.Get(&fv1.Function{ Metadata: metav1.ObjectMeta{ Namespace: namespace, Name: functionName, @@ -187,7 +186,7 @@ func (frr *functionReferenceResolver) resolveByFunctionWeights(namespace string, return nil, fmt.Errorf("function %v does not exist", functionName) } - f := obj.(*crd.Function) + f := obj.(*fv1.Function) functionMetadataMap[f.Metadata.Name] = &f.Metadata sumPrefix = sumPrefix + functionWeight fnWtDistrList = append(fnWtDistrList, FunctionWeightDistribution{ diff --git a/router/functionServiceMap.go b/pkg/router/functionServiceMap.go similarity index 98% rename from router/functionServiceMap.go rename to pkg/router/functionServiceMap.go index 414e6bc9..9e99c79d 100644 --- a/router/functionServiceMap.go +++ b/pkg/router/functionServiceMap.go @@ -23,7 +23,7 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/cache" + "github.com/fission/fission/pkg/cache" ) type ( diff --git a/router/functionServiceMap_test.go b/pkg/router/functionServiceMap_test.go similarity index 100% rename from router/functionServiceMap_test.go rename to pkg/router/functionServiceMap_test.go diff --git a/router/httpTriggers.go b/pkg/router/httpTriggers.go similarity index 89% rename from router/httpTriggers.go rename to pkg/router/httpTriggers.go index 14f9c54f..00a7cf4c 100644 --- a/router/httpTriggers.go +++ b/pkg/router/httpTriggers.go @@ -29,10 +29,11 @@ import ( "k8s.io/client-go/rest" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission" - "github.com/fission/fission/crd" - executorClient "github.com/fission/fission/executor/client" - "github.com/fission/fission/throttler" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + executorClient "github.com/fission/fission/pkg/executor/client" + "github.com/fission/fission/pkg/throttler" + "github.com/fission/fission/pkg/utils" ) type HTTPTriggerSet struct { @@ -45,10 +46,10 @@ type HTTPTriggerSet struct { executor *executorClient.Client resolver *functionReferenceResolver crdClient *rest.RESTClient - triggers []crd.HTTPTrigger + triggers []fv1.HTTPTrigger triggerStore k8sCache.Store triggerController k8sCache.Controller - functions []crd.Function + functions []fv1.Function funcStore k8sCache.Store funcController k8sCache.Controller recorderSet *RecorderSet @@ -64,7 +65,7 @@ func makeHTTPTriggerSet(logger *zap.Logger, fmap *functionServiceMap, frmap *fun httpTriggerSet := &HTTPTriggerSet{ logger: logger.Named("http_trigger_set"), functionServiceMap: fmap, - triggers: []crd.HTTPTrigger{}, + triggers: []fv1.HTTPTrigger{}, fissionClient: fissionClient, kubeClient: kubeClient, executor: executor, @@ -219,7 +220,7 @@ func (ts *HTTPTriggerSet) getRouter() *mux.Router { isDebugEnv: ts.isDebugEnv, svcAddrUpdateThrottler: ts.svcAddrUpdateThrottler, } - muxRouter.HandleFunc(fission.UrlForFunction(function.Metadata.Name, function.Metadata.Namespace), fh.handler) + muxRouter.HandleFunc(utils.UrlForFunction(function.Metadata.Name, function.Metadata.Namespace), fh.handler) } // Healthz endpoint for the router. @@ -228,17 +229,17 @@ func (ts *HTTPTriggerSet) getRouter() *mux.Router { return muxRouter } -func (ts *HTTPTriggerSet) updateTriggerStatusFailed(ht *crd.HTTPTrigger, err error) { +func (ts *HTTPTriggerSet) updateTriggerStatusFailed(ht *fv1.HTTPTrigger, err error) { // TODO } func (ts *HTTPTriggerSet) initTriggerController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(ts.crdClient, "httptriggers", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.HTTPTrigger{}, resyncPeriod, + store, controller := k8sCache.NewInformer(listWatch, &fv1.HTTPTrigger{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - trigger := obj.(*crd.HTTPTrigger) + trigger := obj.(*fv1.HTTPTrigger) go createIngress(ts.logger, trigger, ts.kubeClient) ts.syncTriggers() // Check if this trigger's function needs to be recorded @@ -257,13 +258,13 @@ func (ts *HTTPTriggerSet) initTriggerController() (k8sCache.Store, k8sCache.Cont }, DeleteFunc: func(obj interface{}) { ts.syncTriggers() - trigger := obj.(*crd.HTTPTrigger) + trigger := obj.(*fv1.HTTPTrigger) go deleteIngress(ts.logger, trigger, ts.kubeClient) go ts.recorderSet.DeleteTriggerFromRecorderMap(trigger) }, UpdateFunc: func(oldObj interface{}, newObj interface{}) { - oldTrigger := oldObj.(*crd.HTTPTrigger) - newTrigger := newObj.(*crd.HTTPTrigger) + oldTrigger := oldObj.(*fv1.HTTPTrigger) + newTrigger := newObj.(*fv1.HTTPTrigger) if oldTrigger.Metadata.ResourceVersion == newTrigger.Metadata.ResourceVersion { return @@ -279,19 +280,19 @@ func (ts *HTTPTriggerSet) initTriggerController() (k8sCache.Store, k8sCache.Cont func (ts *HTTPTriggerSet) initFunctionController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(ts.crdClient, "functions", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.Function{}, resyncPeriod, + store, controller := k8sCache.NewInformer(listWatch, &fv1.Function{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { ts.syncTriggers() }, DeleteFunc: func(obj interface{}) { - function := obj.(*crd.Function) + function := obj.(*fv1.Function) ts.syncTriggers() go ts.recorderSet.DeleteFunctionFromRecorderMap(function) }, UpdateFunc: func(oldObj interface{}, newObj interface{}) { - oldFn := oldObj.(*crd.Function) - fn := newObj.(*crd.Function) + oldFn := oldObj.(*fv1.Function) + fn := newObj.(*fv1.Function) if oldFn.Metadata.ResourceVersion == fn.Metadata.ResourceVersion { return @@ -321,19 +322,19 @@ func (ts *HTTPTriggerSet) initFunctionController() (k8sCache.Store, k8sCache.Con func (ts *HTTPTriggerSet) initRecorderController() (k8sCache.Store, k8sCache.Controller) { resyncPeriod := 30 * time.Second listWatch := k8sCache.NewListWatchFromClient(ts.crdClient, "recorders", metav1.NamespaceAll, fields.Everything()) - store, controller := k8sCache.NewInformer(listWatch, &crd.Recorder{}, resyncPeriod, + store, controller := k8sCache.NewInformer(listWatch, &fv1.Recorder{}, resyncPeriod, k8sCache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - recorder := obj.(*crd.Recorder) + recorder := obj.(*fv1.Recorder) ts.recorderSet.newRecorder(recorder) }, DeleteFunc: func(obj interface{}) { - recorder := obj.(*crd.Recorder) + recorder := obj.(*fv1.Recorder) ts.recorderSet.disableRecorder(recorder) }, UpdateFunc: func(oldObj, newObj interface{}) { - oldRecorder := oldObj.(*crd.Recorder) - newRecorder := newObj.(*crd.Recorder) + oldRecorder := oldObj.(*fv1.Recorder) + newRecorder := newObj.(*fv1.Recorder) ts.recorderSet.updateRecorder(oldRecorder, newRecorder) }, }, @@ -355,17 +356,17 @@ func (ts *HTTPTriggerSet) updateRouter() { for range ts.updateRouterRequestChannel { // get triggers latestTriggers := ts.triggerStore.List() - triggers := make([]crd.HTTPTrigger, len(latestTriggers)) + triggers := make([]fv1.HTTPTrigger, len(latestTriggers)) for _, t := range latestTriggers { - triggers = append(triggers, *t.(*crd.HTTPTrigger)) + triggers = append(triggers, *t.(*fv1.HTTPTrigger)) } ts.triggers = triggers // get functions latestFunctions := ts.funcStore.List() - functions := make([]crd.Function, len(latestFunctions)) + functions := make([]fv1.Function, len(latestFunctions)) for _, f := range latestFunctions { - functions = append(functions, *f.(*crd.Function)) + functions = append(functions, *f.(*fv1.Function)) } ts.functions = functions diff --git a/router/ingress.go b/pkg/router/ingress.go similarity index 92% rename from router/ingress.go rename to pkg/router/ingress.go index 28ae3477..a70fd11d 100644 --- a/router/ingress.go +++ b/pkg/router/ingress.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) var podNamespace string @@ -38,7 +38,7 @@ func init() { } } -func createIngress(logger *zap.Logger, trigger *crd.HTTPTrigger, kubeClient *kubernetes.Clientset) { +func createIngress(logger *zap.Logger, trigger *fv1.HTTPTrigger, kubeClient *kubernetes.Clientset) { if !trigger.Spec.CreateIngress { logger.Info("skipping creation of ingress for trigger", zap.String("trigger", trigger.Metadata.Name)) @@ -93,7 +93,7 @@ func createIngress(logger *zap.Logger, trigger *crd.HTTPTrigger, kubeClient *kub logger.Info("created ingress successfully for trigger", zap.String("trigger", trigger.Metadata.Name)) } -func getDeployLabels(trigger *crd.HTTPTrigger) map[string]string { +func getDeployLabels(trigger *fv1.HTTPTrigger) map[string]string { return map[string]string{ "triggerName": trigger.Metadata.Name, "functionName": trigger.Spec.FunctionReference.Name, @@ -101,7 +101,7 @@ func getDeployLabels(trigger *crd.HTTPTrigger) map[string]string { } } -func deleteIngress(logger *zap.Logger, trigger *crd.HTTPTrigger, kubeClient *kubernetes.Clientset) { +func deleteIngress(logger *zap.Logger, trigger *fv1.HTTPTrigger, kubeClient *kubernetes.Clientset) { if !trigger.Spec.CreateIngress { return } @@ -122,7 +122,7 @@ func deleteIngress(logger *zap.Logger, trigger *crd.HTTPTrigger, kubeClient *kub } -func updateIngress(logger *zap.Logger, oldT *crd.HTTPTrigger, newT *crd.HTTPTrigger, kubeClient *kubernetes.Clientset) { +func updateIngress(logger *zap.Logger, oldT *fv1.HTTPTrigger, newT *fv1.HTTPTrigger, kubeClient *kubernetes.Clientset) { if oldT.Spec.CreateIngress == false && newT.Spec.CreateIngress == true { createIngress(logger, newT, kubeClient) diff --git a/router/metrics.go b/pkg/router/metrics.go similarity index 100% rename from router/metrics.go rename to pkg/router/metrics.go diff --git a/router/mutablemux.go b/pkg/router/mutablemux.go similarity index 100% rename from router/mutablemux.go rename to pkg/router/mutablemux.go diff --git a/router/mutablemux_test.go b/pkg/router/mutablemux_test.go similarity index 100% rename from router/mutablemux_test.go rename to pkg/router/mutablemux_test.go diff --git a/router/recorderController.go b/pkg/router/recorderController.go similarity index 88% rename from router/recorderController.go rename to pkg/router/recorderController.go index 39be463d..e51e55f1 100644 --- a/router/recorderController.go +++ b/pkg/router/recorderController.go @@ -5,7 +5,7 @@ import ( "k8s.io/client-go/rest" k8sCache "k8s.io/client-go/tools/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) type RecorderSet struct { @@ -36,7 +36,7 @@ func MakeRecorderSet(logger *zap.Logger, httpTriggerSet *HTTPTriggerSet, crdClie } // All new recorders are by default enabled -func (rs *RecorderSet) newRecorder(r *crd.Recorder) { +func (rs *RecorderSet) newRecorder(r *fv1.Recorder) { function := r.Spec.Function triggers := r.Spec.Triggers @@ -48,7 +48,7 @@ func (rs *RecorderSet) newRecorder(r *crd.Recorder) { if needTrackByFunction { for _, t := range rs.httpTriggerSet.triggerStore.List() { - trigger := *t.(*crd.HTTPTrigger) + trigger := *t.(*fv1.HTTPTrigger) if trigger.Spec.FunctionReference.Name == function { rs.triggerRecorderMap.assign(trigger.Metadata.Name, r) } @@ -63,7 +63,7 @@ func (rs *RecorderSet) newRecorder(r *crd.Recorder) { } // TODO: Delete or disable? -func (rs *RecorderSet) disableRecorder(r *crd.Recorder) { +func (rs *RecorderSet) disableRecorder(r *fv1.Recorder) { function := r.Spec.Function triggers := r.Spec.Triggers @@ -95,7 +95,7 @@ func (rs *RecorderSet) disableRecorder(r *crd.Recorder) { } else { // Account for implicitly added triggers for _, t := range rs.httpTriggerSet.triggerStore.List() { - trigger := *t.(*crd.HTTPTrigger) + trigger := *t.(*fv1.HTTPTrigger) if trigger.Spec.FunctionReference.Name == function { err := rs.triggerRecorderMap.remove(trigger.Metadata.Name) if err != nil { @@ -112,7 +112,7 @@ func (rs *RecorderSet) disableRecorder(r *crd.Recorder) { rs.httpTriggerSet.syncTriggers() } -func (rs *RecorderSet) updateRecorder(old *crd.Recorder, newer *crd.Recorder) { +func (rs *RecorderSet) updateRecorder(old *fv1.Recorder, newer *fv1.Recorder) { if newer.Spec.Enabled == true { rs.newRecorder(newer) // TODO: Test this } else { @@ -120,14 +120,14 @@ func (rs *RecorderSet) updateRecorder(old *crd.Recorder, newer *crd.Recorder) { } } -func (rs *RecorderSet) DeleteTriggerFromRecorderMap(trigger *crd.HTTPTrigger) { +func (rs *RecorderSet) DeleteTriggerFromRecorderMap(trigger *fv1.HTTPTrigger) { err := rs.triggerRecorderMap.remove(trigger.Metadata.Name) if err != nil { rs.logger.Error("failed to remove trigger from triggerRecorderMap", zap.Error(err)) } } -func (rs *RecorderSet) DeleteFunctionFromRecorderMap(function *crd.Function) { +func (rs *RecorderSet) DeleteFunctionFromRecorderMap(function *fv1.Function) { err := rs.functionRecorderMap.remove(function.Metadata.Name) if err != nil { rs.logger.Error("failed to remove function from functionRecorderMap", zap.Error(err)) diff --git a/router/router.go b/pkg/router/router.go similarity index 96% rename from router/router.go rename to pkg/router/router.go index 8f6d5bce..da98a3d3 100644 --- a/router/router.go +++ b/pkg/router/router.go @@ -53,10 +53,10 @@ import ( "go.opencensus.io/trace" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" - executorClient "github.com/fission/fission/executor/client" - "github.com/fission/fission/throttler" + "github.com/fission/fission/pkg/crd" + executorClient "github.com/fission/fission/pkg/executor/client" + "github.com/fission/fission/pkg/throttler" + "github.com/fission/fission/pkg/utils" ) // request url ---[mux]---> Function(name,uid) ----[fmap]----> k8s service url @@ -66,7 +66,7 @@ import ( func router(ctx context.Context, logger *zap.Logger, httpTriggerSet *HTTPTriggerSet, resolver *functionReferenceResolver) *mutableRouter { muxRouter := mux.NewRouter() mr := NewMutableRouter(logger, muxRouter) - muxRouter.Use(fission.LoggingMiddleware(logger)) + muxRouter.Use(utils.LoggingMiddleware(logger)) httpTriggerSet.subscribeRouter(ctx, mr, resolver) return mr } @@ -92,7 +92,7 @@ func serveMetric(logger *zap.Logger) { func Start(logger *zap.Logger, port int, executorUrl string) { // setup a signal handler for SIGTERM - fission.SetupStackTraceHandler() + utils.SetupStackTraceHandler() _ = MakeAnalytics("") diff --git a/router/router_test.go b/pkg/router/router_test.go similarity index 91% rename from router/router_test.go rename to pkg/router/router_test.go index d4e60adb..f6609a3f 100644 --- a/router/router_test.go +++ b/pkg/router/router_test.go @@ -22,12 +22,12 @@ import ( "testing" "time" + "github.com/fission/fission/pkg/types" "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/throttler" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/throttler" ) func TestRouter(t *testing.T) { @@ -35,8 +35,8 @@ func TestRouter(t *testing.T) { fn := &metav1.ObjectMeta{Name: "foo", Namespace: metav1.NamespaceDefault} // and a reference to it - fr := fission.FunctionReference{ - Type: fission.FunctionReferenceTypeFunctionName, + fr := fv1.FunctionReference{ + Type: types.FunctionReferenceTypeFunctionName, Name: fn.Name, } @@ -65,13 +65,13 @@ func TestRouter(t *testing.T) { }, false, throttler.MakeThrottler(30*time.Second)) triggerUrl := "/foo" triggers.triggers = append(triggers.triggers, - crd.HTTPTrigger{ + fv1.HTTPTrigger{ Metadata: metav1.ObjectMeta{ Name: "xxx", Namespace: metav1.NamespaceDefault, ResourceVersion: "1234", }, - Spec: fission.HTTPTriggerSpec{ + Spec: fv1.HTTPTriggerSpec{ RelativeURL: triggerUrl, FunctionReference: fr, Method: "GET", diff --git a/router/triggerRecorderMap.go b/pkg/router/triggerRecorderMap.go similarity index 78% rename from router/triggerRecorderMap.go rename to pkg/router/triggerRecorderMap.go index 48dea4ae..8284b2d2 100644 --- a/router/triggerRecorderMap.go +++ b/pkg/router/triggerRecorderMap.go @@ -21,15 +21,15 @@ import ( "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/cache" - "github.com/fission/fission/crd" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/cache" + ferror "github.com/fission/fission/pkg/error" ) type ( triggerRecorderMap struct { logger *zap.Logger - cache *cache.Cache // map[string]*crd.Recorder + cache *cache.Cache // map[string]*fv1.Recorder } ) @@ -40,19 +40,19 @@ func makeTriggerRecorderMap(logger *zap.Logger, expiry time.Duration) *triggerRe } } -func (trmap *triggerRecorderMap) lookup(trigger string) (*crd.Recorder, error) { +func (trmap *triggerRecorderMap) lookup(trigger string) (*fv1.Recorder, error) { item, err := trmap.cache.Get(trigger) if err != nil { return nil, err } - u := item.(*crd.Recorder) + u := item.(*fv1.Recorder) return u, nil } -func (trmap *triggerRecorderMap) assign(trigger string, recorder *crd.Recorder) { +func (trmap *triggerRecorderMap) assign(trigger string, recorder *fv1.Recorder) { err, _ := trmap.cache.Set(trigger, recorder) if err != nil { - if e, ok := err.(fission.Error); ok && e.Code == fission.ErrorNameExists { + if e, ok := err.(ferror.Error); ok && e.Code == ferror.ErrorNameExists { return } trmap.logger.Error("error caching recorder for function name with a different value", zap.Error(err)) diff --git a/router/util.go b/pkg/router/util.go similarity index 100% rename from router/util.go rename to pkg/router/util.go diff --git a/router/util_test.go b/pkg/router/util_test.go similarity index 100% rename from router/util_test.go rename to pkg/router/util_test.go diff --git a/storagesvc/README.md b/pkg/storagesvc/README.md similarity index 100% rename from storagesvc/README.md rename to pkg/storagesvc/README.md diff --git a/storagesvc/archivePruner.go b/pkg/storagesvc/archivePruner.go similarity index 99% rename from storagesvc/archivePruner.go rename to pkg/storagesvc/archivePruner.go index 80770448..63d32327 100644 --- a/storagesvc/archivePruner.go +++ b/pkg/storagesvc/archivePruner.go @@ -22,7 +22,7 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" ) type ArchivePruner struct { diff --git a/storagesvc/client/client.go b/pkg/storagesvc/client/client.go similarity index 98% rename from storagesvc/client/client.go rename to pkg/storagesvc/client/client.go index ecf590ca..6ffab97c 100644 --- a/storagesvc/client/client.go +++ b/pkg/storagesvc/client/client.go @@ -33,7 +33,7 @@ import ( "go.opencensus.io/plugin/ochttp" "golang.org/x/net/context/ctxhttp" - "github.com/fission/fission/storagesvc" + "github.com/fission/fission/pkg/storagesvc" ) type ( diff --git a/storagesvc/client/storagesvc_test.go b/pkg/storagesvc/client/storagesvc_test.go similarity index 98% rename from storagesvc/client/storagesvc_test.go rename to pkg/storagesvc/client/storagesvc_test.go index e7337323..ba925e0c 100644 --- a/storagesvc/client/storagesvc_test.go +++ b/pkg/storagesvc/client/storagesvc_test.go @@ -29,7 +29,7 @@ import ( "github.com/dchest/uniuri" "go.uber.org/zap" - "github.com/fission/fission/storagesvc" + "github.com/fission/fission/pkg/storagesvc" ) func panicIf(err error) { diff --git a/storagesvc/storagesvc.go b/pkg/storagesvc/storagesvc.go similarity index 98% rename from storagesvc/storagesvc.go rename to pkg/storagesvc/storagesvc.go index 74be79c1..12069236 100644 --- a/storagesvc/storagesvc.go +++ b/pkg/storagesvc/storagesvc.go @@ -30,7 +30,7 @@ import ( "go.opencensus.io/plugin/ochttp" "go.uber.org/zap" - "github.com/fission/fission" + "github.com/fission/fission/pkg/utils" ) type ( @@ -183,7 +183,7 @@ func (ss *StorageService) Start(port int) { address := fmt.Sprintf(":%v", port) - r.Use(fission.LoggingMiddleware(ss.logger)) + r.Use(utils.LoggingMiddleware(ss.logger)) err := http.ListenAndServe(address, &ochttp.Handler{ Handler: r, // Propagation: &b3.HTTPFormat{}, @@ -194,7 +194,7 @@ func (ss *StorageService) Start(port int) { func RunStorageService(logger *zap.Logger, storageType StorageType, storagePath string, containerName string, port int, enablePruner bool) *StorageService { // setup a signal handler for SIGTERM - fission.SetupStackTraceHandler() + utils.SetupStackTraceHandler() // create a storage client storageClient, err := MakeStowClient(logger, storageType, storagePath, containerName) diff --git a/storagesvc/stowClient.go b/pkg/storagesvc/stowClient.go similarity index 100% rename from storagesvc/stowClient.go rename to pkg/storagesvc/stowClient.go diff --git a/storagesvc/util.go b/pkg/storagesvc/util.go similarity index 100% rename from storagesvc/util.go rename to pkg/storagesvc/util.go diff --git a/throttler/throttler.go b/pkg/throttler/throttler.go similarity index 100% rename from throttler/throttler.go rename to pkg/throttler/throttler.go diff --git a/timer/main.go b/pkg/timer/main.go similarity index 93% rename from timer/main.go rename to pkg/timer/main.go index 8c9231dc..f33bbaf1 100644 --- a/timer/main.go +++ b/pkg/timer/main.go @@ -20,8 +20,8 @@ import ( "github.com/pkg/errors" "go.uber.org/zap" - "github.com/fission/fission/crd" - "github.com/fission/fission/publisher" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/publisher" ) func Start(logger *zap.Logger, routerUrl string) error { diff --git a/timer/timer.go b/pkg/timer/timer.go similarity index 85% rename from timer/timer.go rename to pkg/timer/timer.go index e9f2d940..b8343d5a 100644 --- a/timer/timer.go +++ b/pkg/timer/timer.go @@ -20,9 +20,10 @@ import ( "github.com/robfig/cron" "go.uber.org/zap" - "github.com/fission/fission" - "github.com/fission/fission/crd" - "github.com/fission/fission/publisher" + fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/publisher" + "github.com/fission/fission/pkg/utils" ) type requestType int @@ -41,14 +42,14 @@ type ( timerRequest struct { requestType - triggers []crd.TimeTrigger + triggers []fv1.TimeTrigger responseChannel chan *timerResponse } timerResponse struct { error } timerTriggerWithCron struct { - trigger crd.TimeTrigger + trigger fv1.TimeTrigger cron *cron.Cron } ) @@ -64,7 +65,7 @@ func MakeTimer(logger *zap.Logger, publisher publisher.Publisher) *Timer { return timer } -func (timer *Timer) Sync(triggers []crd.TimeTrigger) error { +func (timer *Timer) Sync(triggers []fv1.TimeTrigger) error { req := &timerRequest{ requestType: SYNC, triggers: triggers, @@ -86,7 +87,7 @@ func (timer *Timer) svc() { } } -func (timer *Timer) syncCron(triggers []crd.TimeTrigger) error { +func (timer *Timer) syncCron(triggers []fv1.TimeTrigger) error { // add new triggers or update existing ones triggerMap := make(map[string]bool) for _, t := range triggers { @@ -124,7 +125,7 @@ func (timer *Timer) syncCron(triggers []crd.TimeTrigger) error { return nil } -func (timer *Timer) newCron(t crd.TimeTrigger) *cron.Cron { +func (timer *Timer) newCron(t fv1.TimeTrigger) *cron.Cron { c := cron.New() c.AddFunc(t.Spec.Cron, func() { headers := map[string]string{ @@ -134,7 +135,7 @@ func (timer *Timer) newCron(t crd.TimeTrigger) *cron.Cron { // with the addition of multi-tenancy, the users can create functions in any namespace. however, // the triggers can only be created in the same namespace as the function. // so essentially, function namespace = trigger namespace. - (*timer.publisher).Publish("", headers, fission.UrlForFunction(t.Spec.FunctionReference.Name, t.Metadata.Namespace)) + (*timer.publisher).Publish("", headers, utils.UrlForFunction(t.Spec.FunctionReference.Name, t.Metadata.Namespace)) }) c.Start() timer.logger.Info("added new cron for time trigger", zap.String("trigger", t.Metadata.Name)) diff --git a/timer/timerSync.go b/pkg/timer/timerSync.go similarity index 93% rename from timer/timerSync.go rename to pkg/timer/timerSync.go index c6d2fec5..bfe74ece 100644 --- a/timer/timerSync.go +++ b/pkg/timer/timerSync.go @@ -22,8 +22,8 @@ import ( "go.uber.org/zap" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/fission/fission" - "github.com/fission/fission/crd" + "github.com/fission/fission/pkg/crd" + "github.com/fission/fission/pkg/utils" ) type ( @@ -48,7 +48,7 @@ func (ws *TimerSync) syncSvc() { for { triggers, err := ws.fissionClient.TimeTriggers(metav1.NamespaceAll).List(metav1.ListOptions{}) if err != nil { - if fission.IsNetworkError(err) { + if utils.IsNetworkError(err) { ws.logger.Info("encountered a network error - will retry", zap.Error(err)) time.Sleep(5 * time.Second) continue diff --git a/types.go b/pkg/types/types.go similarity index 64% rename from types.go rename to pkg/types/types.go index 8ad32a1d..b8d96ea7 100644 --- a/types.go +++ b/pkg/types/types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fission +package types import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -22,51 +22,6 @@ import ( fv1 "github.com/fission/fission/pkg/apis/fission.io/v1" ) -type ( - ChecksumType = fv1.ChecksumType - Checksum = fv1.Checksum - ArchiveType = fv1.ArchiveType - Archive = fv1.Archive - EnvironmentReference = fv1.EnvironmentReference - SecretReference = fv1.SecretReference - ConfigMapReference = fv1.ConfigMapReference - BuildStatus = fv1.BuildStatus - PackageSpec = fv1.PackageSpec - PackageStatus = fv1.PackageStatus - PackageRef = fv1.PackageRef - FunctionPackageRef = fv1.FunctionPackageRef - ExecutorType = fv1.ExecutorType - StrategyType = fv1.StrategyType - FunctionSpec = fv1.FunctionSpec - InvokeStrategy = fv1.InvokeStrategy - ExecutionStrategy = fv1.ExecutionStrategy - FunctionReferenceType = fv1.FunctionReferenceType - FunctionReference = fv1.FunctionReference - Runtime = fv1.Runtime - Builder = fv1.Builder - EnvironmentSpec = fv1.EnvironmentSpec - AllowedFunctionsPerContainer = fv1.AllowedFunctionsPerContainer - HTTPTriggerSpec = fv1.HTTPTriggerSpec - KubernetesWatchTriggerSpec = fv1.KubernetesWatchTriggerSpec - MessageQueueType = fv1.MessageQueueType - MessageQueueTriggerSpec = fv1.MessageQueueTriggerSpec - TimeTriggerSpec = fv1.TimeTriggerSpec - RecorderSpec = fv1.RecorderSpec - CanaryConfigSpec = fv1.CanaryConfigSpec - CanaryConfigStatus = fv1.CanaryConfigStatus - FailureType = fv1.FailureType -) - -type ( - // Errors returned by the Fission API. - Error struct { - Code errorCode `json:"code"` - Message string `json:"message"` - } - - errorCode int -) - // // Fission-Environment interface. The following types are not // exposed in the Fission API, but rather used by Fission to @@ -81,14 +36,14 @@ type ( } FunctionFetchRequest struct { - FetchType FetchRequestType `json:"fetchType"` - Package metav1.ObjectMeta `json:"package"` - Url string `json:"url"` - StorageSvcUrl string `json:"storagesvcurl"` - Filename string `json:"filename"` - Secrets []SecretReference `json:"secretList"` - ConfigMaps []ConfigMapReference `json:"configMapList"` - KeepArchive bool `json:"keeparchive"` + FetchType FetchRequestType `json:"fetchType"` + Package metav1.ObjectMeta `json:"package"` + Url string `json:"url"` + StorageSvcUrl string `json:"storagesvcurl"` + Filename string `json:"filename"` + Secrets []fv1.SecretReference `json:"secretList"` + ConfigMaps []fv1.ConfigMapReference `json:"configMapList"` + KeepArchive bool `json:"keeparchive"` } FunctionLoadRequest struct { @@ -124,8 +79,8 @@ type ( // ArchiveUploadResponse defines the download url of an archive and // its checksum. ArchiveUploadResponse struct { - ArchiveDownloadUrl string `json:"archiveDownloadUrl"` - Checksum Checksum `json:"checksum"` + ArchiveDownloadUrl string `json:"archiveDownloadUrl"` + Checksum fv1.Checksum `json:"checksum"` } ) @@ -211,32 +166,6 @@ const ( ) -const ( - ErrorInternal = iota - - ErrorNotAuthorized - ErrorNotFound - ErrorNameExists - ErrorInvalidArgument - ErrorNoSpace - ErrorNotImplmented - ErrorChecksumFail - ErrorSizeLimitExceeded -) - -// must match order and len of the above const -var errorDescriptions = []string{ - "Internal error", - "Not authorized", - "Resource not found", - "Resource exists", - "Invalid argument", - "No space", - "Not implemented", - "Checksum verification failed", - "Size limit exceeded", -} - const ( ArchiveLiteralSizeLimit int64 = 256 * 1024 ) diff --git a/commonrbacutil.go b/pkg/utils/rbacutils.go similarity index 97% rename from commonrbacutil.go rename to pkg/utils/rbacutils.go index 439518db..c9dc1816 100644 --- a/commonrbacutil.go +++ b/pkg/utils/rbacutils.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fission +package utils import ( "fmt" @@ -34,7 +34,7 @@ import ( // This file has util functions needed for setting up and cleaning up RBAC objects. const ( - MaxRetries = 10 + maxRetries = 10 ) // MakeSAObj returns a ServiceAccount object with the given SA name and namespace @@ -119,7 +119,7 @@ func AddSaToRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernetes.Cli return err } - for i := 0; i < MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { _, err = k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Patch(roleBinding, types.JSONPatchType, patchJson) if err == nil { logger.Debug("patched rolebinding", @@ -170,13 +170,13 @@ func AddSaToRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernetes.Cli return errors.Wrap(err, "error returned by rolebinding patch") } - return errors.Wrapf(err, "exceeded max retries (%d) adding SA: %s.%s to rolebinding: %s.%s, giving up", MaxRetries, sa, saNamespace, roleBinding, roleBindingNs) + return errors.Wrapf(err, "exceeded max retries (%d) adding SA: %s.%s to rolebinding: %s.%s, giving up", maxRetries, sa, saNamespace, roleBinding, roleBindingNs) } // RemoveSAFromRoleBindingWithRetries removes an SA from the rolebinding passed as parameter. If this is the only SA in // the rolebinding, then it deletes the rolebinding object. func RemoveSAFromRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernetes.Clientset, roleBinding, roleBindingNs string, saToRemove map[string]bool) (err error) { - for i := 0; i < MaxRetries; i++ { + for i := 0; i < maxRetries; i++ { rbObj, err := k8sClient.RbacV1beta1().RoleBindings(roleBindingNs).Get( roleBinding, metav1.GetOptions{}) if err != nil { @@ -229,7 +229,7 @@ func RemoveSAFromRoleBindingWithRetries(logger *zap.Logger, k8sClient *kubernete } } - return errors.Wrapf(err, "max retries: %d exceeded for removing SA's: %v from rolebinding %s.%s, giving up", MaxRetries, saToRemove, roleBinding, roleBindingNs) + return errors.Wrapf(err, "max retries: %d exceeded for removing SA's: %v from rolebinding %s.%s, giving up", maxRetries, saToRemove, roleBinding, roleBindingNs) } // SetupRoleBinding adds a role to a service account if the rolebinding object is already present in the namespace. diff --git a/common.go b/pkg/utils/utils.go similarity index 99% rename from common.go rename to pkg/utils/utils.go index 74927925..d3150a61 100644 --- a/common.go +++ b/pkg/utils/utils.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fission +package utils import ( "fmt" diff --git a/v1/types.go b/pkg/v1/types.go similarity index 100% rename from v1/types.go rename to pkg/v1/types.go diff --git a/skaffold.yaml b/skaffold.yaml index 331bd036..8926b022 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -21,13 +21,13 @@ build: - image: /fission context: . docker: - dockerfile: fission-bundle/Dockerfile.fission-bundle + dockerfile: cmd/fission-bundle/Dockerfile.fission-bundle - image: /fetcher docker: - dockerfile: environments/fetcher/cmd/Dockerfile.fission-fetcher + dockerfile: cmd/fetcher/Dockerfile.fission-fetcher - image: /preupgradechecks docker: - dockerfile: preupgradechecks/Dockerfile.fission-preupgradechecks + dockerfile: cmd/preupgradechecks/Dockerfile.fission-preupgradechecks tagPolicy: envTemplate: template: "{{.IMAGE_NAME}}:skaffold-test" diff --git a/test/test_utils.sh b/test/test_utils.sh index f54c5b63..5b5ffd98 100755 --- a/test/test_utils.sh +++ b/test/test_utils.sh @@ -8,10 +8,7 @@ set -euo pipefail -ROOT_RELPATH=$(dirname $0)/.. -pushd $ROOT_RELPATH -ROOT=$(pwd) -popd +ROOT=`realpath $(dirname $0)/..` travis_fold_start() { echo -e "travis_fold:start:$1\r\033[33;1m$2\033[0m" @@ -60,7 +57,7 @@ build_and_push_pre_upgrade_check_image() { image_tag=$1 travis_fold_start build_and_push_pre_upgrade_check_image $image_tag - docker build -t $image_tag -f $ROOT/preupgradechecks/Dockerfile.fission-preupgradechecks --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . + docker build -t $image_tag -f $ROOT/cmd/preupgradechecks/Dockerfile.fission-preupgradechecks --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . gcloud_login @@ -72,7 +69,7 @@ build_and_push_fission_bundle() { image_tag=$1 travis_fold_start build_and_push_fission_bundle $image_tag - docker build -q -t $image_tag -f $ROOT/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . + docker build -q -t $image_tag -f $ROOT/cmd/fission-bundle/Dockerfile.fission-bundle --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . gcloud_login @@ -84,7 +81,7 @@ build_and_push_fetcher() { image_tag=$1 travis_fold_start build_and_push_fetcher $image_tag - docker build -q -t $image_tag -f $ROOT/environments/fetcher/cmd/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . + docker build -q -t $image_tag -f $ROOT/cmd/fetcher/Dockerfile.fission-fetcher --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . gcloud_login @@ -97,7 +94,7 @@ build_and_push_builder() { image_tag=$1 travis_fold_start build_and_push_builder $image_tag - docker build -q -t $image_tag -f $ROOT/builder/cmd/Dockerfile.fission-builder --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . + docker build -q -t $image_tag -f $ROOT/cmd/builder/Dockerfile.fission-builder --build-arg GITCOMMIT=$(getGitCommit) --build-arg BUILDDATE=$(getDate) --build-arg BUILDVERSION=$(getVersion) . gcloud_login @@ -139,7 +136,7 @@ build_and_push_env_builder() { build_fission_cli() { travis_fold_start build_fission_cli "fission cli" - pushd $ROOT/fission + pushd $ROOT/cmd/fission-cli go build . popd travis_fold_end build_fission_cli @@ -158,7 +155,7 @@ set_environment() { export FISSION_NATS_STREAMING_URL="http://defaultFissionAuthToken@$(kubectl -n $ns get svc nats-streaming -o jsonpath='{...ip}:{.spec.ports[0].port}')" # set path to include cli - export PATH=$ROOT/fission:$PATH + export PATH=$ROOT/cmd/fission-cli:$PATH } generate_test_id() { diff --git a/test/tests/mqtrigger/kafka/test_kafka.sh b/test/tests/mqtrigger/kafka/test_kafka.sh index c29b9de8..47c30820 100755 --- a/test/tests/mqtrigger/kafka/test_kafka.sh +++ b/test/tests/mqtrigger/kafka/test_kafka.sh @@ -58,22 +58,6 @@ test_fnmessage() { } export -f test_fnmessage -waitBuild() { - log "Waiting for builder manager to finish the build" - - set +e - while true; do - kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded - if [[ $? -eq 0 ]]; then - break - fi - log "Waiting for build to finish" - sleep 1 - done - set -e -} -export -f waitBuild - cleanup() { log "Cleaning up..." clean_resource_by_id $TEST_ID diff --git a/test/tests/test_buildermgr.sh b/test/tests/test_buildermgr.sh index 24dac847..26bad003 100755 --- a/test/tests/test_buildermgr.sh +++ b/test/tests/test_buildermgr.sh @@ -29,36 +29,6 @@ checkFunctionResponse() { echo $response | grep -i "a: 1 b: {c: 3, d: 4}" } -waitBuild() { - log "Waiting for builder manager to finish the build" - - while true; do - kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done -} -export -f waitBuild - -waitEnvBuilder() { - env=$1 - envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}') - - log "Waiting for env builder to catch up" - - while true; do - kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \ - -o jsonpath='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' | grep "Ready=True" | grep -i "$1" - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done -} -export -f waitEnvBuilder - cleanup() { log "Cleaning up..." clean_resource_by_id $TEST_ID @@ -74,7 +44,7 @@ fi log "Creating python env" fission env create --name $env --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE -timeout 180s bash -c "waitEnvBuilder $env" +timeout 180s bash -c "wait_for_builder $env" log "Creating source pacakage" zip -jr $tmp_dir/demo-src-pkg.zip $ROOT/examples/python/sourcepkg/ diff --git a/test/tests/test_environments/test_go_env.sh b/test/tests/test_environments/test_go_env.sh index 691e121f..e1a54ffb 100755 --- a/test/tests/test_environments/test_go_env.sh +++ b/test/tests/test_environments/test_go_env.sh @@ -26,39 +26,6 @@ env=go-$TEST_ID fn_poolmgr=hello-go-poolmgr-$TEST_ID fn_nd=hello-go-nd-$TEST_ID -wait_for_builder() { - env=$1 - JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' - - # wait for tiller ready - set +e - while true; do - kubectl --namespace fission-builder get pod -l envName=$env -o jsonpath="$JSONPATH" | grep "Ready=True" - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done - set -e -} - -waitBuild() { - log "Waiting for builder manager to finish the build" - - set +e - while true; do - kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done - set -e -} - -export -f wait_for_builder -export -f waitBuild - cd $ROOT/examples/go log "Creating environment for Golang" diff --git a/test/tests/test_environments/test_java_builder.sh b/test/tests/test_environments/test_java_builder.sh index 5710b5e3..31a9b9b0 100755 --- a/test/tests/test_environments/test_java_builder.sh +++ b/test/tests/test_environments/test_java_builder.sh @@ -26,23 +26,6 @@ else log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards." fi -test_pkg() { - echo "Checking package for valid response" - - set +e - while true; do - response0=$(kubectl get -ndefault package $1 -o=jsonpath='{.status.buildstatus}') - echo $response0 | grep -i $2 - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done - set -e -} - -export -f test_pkg - cd $ROOT/examples/jvm/java log "Creating zip from source code" @@ -51,12 +34,14 @@ zip -r $tmp_dir/java-src-pkg.zip * log "Creating Java environment with Java Builder" fission env create --name $env --image $JVM_RUNTIME_IMAGE --version 2 --keeparchive --builder $JVM_BUILDER_IMAGE +timeout 90 bash -c "wait_for_builder $env" + log "Creating package from the source archive" pkg_name=`fission package create --sourcearchive $tmp_dir/java-src-pkg.zip --env $env|cut -d' ' -f 2|cut -d"'" -f 2` log "Created package $pkg_name" log "Checking the status of package" -timeout 400 bash -c "test_pkg $pkg_name 'succeeded'" +timeout 400 bash -c "waitBuild $pkg_name" log "Creating pool manager & new deployment function for Java" fission fn create --name $fn_n --pkg $pkg_name --env $env --entrypoint io.fission.HelloWorld --executortype newdeploy --minscale 1 --maxscale 1 diff --git a/test/tests/test_package_command.sh b/test/tests/test_package_command.sh index c64bf5d8..4121128d 100755 --- a/test/tests/test_package_command.sh +++ b/test/tests/test_package_command.sh @@ -31,21 +31,6 @@ fn2=python-srcbuild2-$TEST_ID fn4=python-deploy4-$TEST_ID fn5=python-deploy5-$TEST_ID -waitBuild() { - log "Waiting for builder manager to finish the build" - - while true; do - status=$(kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}') - if (echo $status | grep succeeded); then - break - else - log "status=$status Waiting for build to finish" - fi - sleep 1 - done -} -export -f waitBuild - checkFunctionResponse() { log "Doing an HTTP GET on the function's route" response=$(curl --retry 5 http://$FISSION_ROUTER/$1) @@ -55,23 +40,6 @@ checkFunctionResponse() { echo $response | grep -i "$2" } -waitEnvBuilder() { - env=$1 - envRV=$(kubectl -n default get environments ${env} -o jsonpath='{.metadata.resourceVersion}') - - log "Waiting for env builder to catch up" - - while true; do - kubectl -n fission-builder get pod -l envName=${env},envResourceVersion=${envRV} \ - -o jsonpath='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' | grep "Ready=True" | grep -i "$env" - if [[ $? -eq 0 ]]; then - break - fi - sleep 1 - done -} -export -f waitEnvBuilder - cleanup() { log "Cleaning up..." clean_resource_by_id $TEST_ID @@ -87,7 +55,7 @@ fi log "Creating python env" fission env create --name $env --image $PYTHON_RUNTIME_IMAGE --builder $PYTHON_BUILDER_IMAGE -timeout 180s bash -c "waitEnvBuilder $env" +timeout 180s bash -c "wait_for_builder $env" # 1) Multiple source files (multiple inputs, Using * expression, from a directory) # Currently only * expression implemented as a test pushd $ROOT/examples/python/ diff --git a/test/tests/test_specs/test_spec_merge/specs/env-nodend.yaml b/test/tests/test_specs/test_spec_merge/specs/env-nodend.yaml index 76c38d21..20bb9681 100644 --- a/test/tests/test_specs/test_spec_merge/specs/env-nodend.yaml +++ b/test/tests/test_specs/test_spec_merge/specs/env-nodend.yaml @@ -69,4 +69,4 @@ spec: - path: "labels" fieldRef: fieldPath: metadata.labels - version: 1 + version: 3 diff --git a/test/utils.sh b/test/utils.sh index 1e8ad276..67c89cd2 100755 --- a/test/utils.sh +++ b/test/utils.sh @@ -18,14 +18,9 @@ clean_resource_by_id() { KUBECTL="kubectl --namespace default" set +e - crds=$($KUBECTL get crd | grep "fission.io" | awk '{print $1}') - crds="$crds configmaps secrets" - for crd in $crds; do - $KUBECTL get $crd -o name | grep $test_id | xargs --no-run-if-empty $KUBECTL delete - done - pkg_list=$(fission package list | grep $test_id | awk '{print $1}') for pkg in $pkg_list; do + fission pkg info --name $pkg fission package delete --name $pkg done @@ -33,6 +28,13 @@ clean_resource_by_id() { for route in $route_list; do fission route delete --name $route done + + crds=$($KUBECTL get crd | grep "fission.io" | awk '{print $1}') + crds="$crds configmaps secrets" + for crd in $crds; do + $KUBECTL get $crd -o name | grep $test_id | xargs --no-run-if-empty $KUBECTL delete + done + set -e } @@ -64,6 +66,39 @@ test_fn() { } export -f test_fn +wait_for_builder() { + env=$1 + JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' + + # wait for tiller ready + set +e + while true; do + kubectl --namespace fission-builder get pod -l envName=$env -o jsonpath="$JSONPATH" | grep "Ready=True" + if [[ $? -eq 0 ]]; then + break + fi + sleep 1 + done + set -e +} +export -f wait_for_builder + +waitBuild() { + log "Waiting for builder manager to finish the build" + + set +e + while true; do + kubectl --namespace default get packages $1 -o jsonpath='{.status.buildstatus}'|grep succeeded + if [[ $? -eq 0 ]]; then + break + fi + sleep 1 + done + set -e +} +export -f waitBuild + + ## Common env parameters export FISSION_NAMESPACE=${FISSION_NAMESPACE:-fission} export FUNCTION_NAMESPACE=${FUNCTION_NAMESPACE:-fission-function}