diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 789bc7cfe4..dfbcfe7639 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -58,8 +58,7 @@ follows. ## Installing Sources Once you've [setup your development environment](#getting-started), install any -of the sources _Github Source_, _AWS SQS Source_, _Camel Source_, _Gcppubsub -Source_, _Kafka Source_ with: +of the sources _Github Source_, _AWS SQS Source_, _Camel Source_, _Kafka Source_ with: ``` ko apply -f contrib// @@ -82,10 +81,9 @@ You can access the Github eventing manager's logs with: kubectl -n knative-sources logs $(kubectl -n knative-sources get pods -l control-plane=github-controller-manager -o name) ``` -_See [contrib/gcppubsub/samples/README.md](gcppubsub/samples/README.md), -[camel/source/samples/README.md](./camel/source/samples/README.md), +_See [camel/source/samples/README.md](./camel/source/samples/README.md), [kafka/source/samples/README.md](./kafka/source/samples/README.md) for -instructions on installing the Gcppubsub Source, Camel Source and Kafka Source._ +instructions on installing the Camel Source and Kafka Source._ ## Iterating diff --git a/Gopkg.lock b/Gopkg.lock index 6c1e0ea84c..3cb41d9c51 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,7 +2,7 @@ [[projects]] - digest = "1:7eae9819951226dbae87c1315b9bb4f6090662e0b405074256e3a9861f6e93fb" + digest = "1:a3a700fde960868375691c0ffb5fac44111249e9e12d47d9bfc9a3faf10f8694" name = "cloud.google.com/go" packages = [ "compute/metadata", @@ -11,9 +11,6 @@ "internal/optional", "internal/version", "monitoring/apiv3", - "pubsub", - "pubsub/apiv1", - "pubsub/internal/distribution", "trace/apiv2", ] pruneopts = "NUT" @@ -1084,7 +1081,6 @@ "googleapis/devtools/cloudtrace/v2", "googleapis/iam/v1", "googleapis/monitoring/v3", - "googleapis/pubsub/v1", "googleapis/rpc/status", "protobuf/field_mask", ] @@ -1713,7 +1709,6 @@ analyzer-name = "dep" analyzer-version = 1 input-imports = [ - "cloud.google.com/go/pubsub", "github.com/Shopify/sarama", "github.com/apache/camel-k/pkg/apis/camel/v1alpha1", "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative", diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 1aec8f58ac..4fa1d8450e 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -2,11 +2,6 @@ aliases: # These aliases are for OWNERS of the various Source implementations. These # Are in addition to the repo level OWNERS. - gcp-pubsub-approvers: - - Harwayne - gcp-pubsub-reviewers: - - Harwayne - github-approvers: - bbrowning github-reviewers: diff --git a/gcppubsub/OWNERS b/gcppubsub/OWNERS deleted file mode 100644 index 44ca4ed92e..0000000000 --- a/gcppubsub/OWNERS +++ /dev/null @@ -1,9 +0,0 @@ -approvers: - - gcp-pubsub-approvers - -reviewers: - - gcp-pubsub-reviewers - -labels: - - area/GCP-PubSub - diff --git a/gcppubsub/PROJECT b/gcppubsub/PROJECT deleted file mode 100644 index ef9cea0ebe..0000000000 --- a/gcppubsub/PROJECT +++ /dev/null @@ -1,3 +0,0 @@ -version: "1" -domain: eventing.knative.dev -repo: knative.dev/eventing-contrib diff --git a/gcppubsub/cmd/controller/main.go b/gcppubsub/cmd/controller/main.go deleted file mode 100644 index 4aa6abd272..0000000000 --- a/gcppubsub/cmd/controller/main.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 2018 The Knative 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" - "go.uber.org/zap/zapcore" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "knative.dev/eventing-contrib/gcppubsub/pkg/apis" - controller "knative.dev/eventing-contrib/gcppubsub/pkg/reconciler" - "knative.dev/pkg/logging/logkey" - "sigs.k8s.io/controller-runtime/pkg/client/config" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/runtime/signals" -) - -func main() { - logCfg := zap.NewProductionConfig() - logCfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - logger, err := logCfg.Build() - if err != nil { - log.Fatal(err) - } - logger = logger.With(zap.String(logkey.ControllerType, "gcppubsub-controller")) - - // Get a config to talk to the apiserver - cfg, err := config.GetConfig() - if err != nil { - log.Fatal(err) - } - - // Create a new Cmd to provide shared dependencies and start components - mgr, err := manager.New(cfg, manager.Options{}) - if err != nil { - log.Fatal(err) - } - - log.Printf("Registering Components.") - - // Setup Scheme for all resources - if err := apis.AddToScheme(mgr.GetScheme()); err != nil { - log.Fatal(err) - } - - // Setup pubsub Controller - if err := controller.Add(mgr, logger.Sugar()); err != nil { - log.Fatal(err) - } - - log.Printf("Starting GCP Pubsub controller.") - - // Start the Cmd - log.Fatal(mgr.Start(signals.SetupSignalHandler())) -} diff --git a/gcppubsub/cmd/receive_adapter/main.go b/gcppubsub/cmd/receive_adapter/main.go deleted file mode 100644 index 3c3ad5d85f..0000000000 --- a/gcppubsub/cmd/receive_adapter/main.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2018 The Knative 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 ( - "flag" - "log" - - "github.com/kelseyhightower/envconfig" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - - "golang.org/x/net/context" - - gcppubsub "knative.dev/eventing-contrib/gcppubsub/pkg/adapter" -) - -type envConfig struct { - // Environment variable containing project id. - Project string `envconfig:"GCPPUBSUB_PROJECT" required:"true"` - - // Environment variable containing the sink URI. - Sink string `envconfig:"SINK_URI" required:"true"` - - // Environment variable containing the transformer URI. - Transformer string `envconfig:"TRANSFORMER_URI" default:""` - - // Environment variable containing the GCP PubSub Topic being - // subscribed to's name. In the form that is unique within the project. E.g. 'laconia', not - // 'projects/my-gcp-project/topics/laconia'. - Topic string `envconfig:"GCPPUBSUB_TOPIC" default:""` - - // Environment variable containing the name of the subscription to use. - Subscription string `envconfig:"GCPPUBSUB_SUBSCRIPTION_ID" required:"true"` -} - -func main() { - flag.Parse() - - ctx := context.Background() - logCfg := zap.NewProductionConfig() - logCfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder - logger, err := logCfg.Build() - if err != nil { - log.Fatalf("Unable to create logger: %v", err) - } - - var env envConfig - if err := envconfig.Process("", &env); err != nil { - logger.Fatal("Failed to process env var", zap.Error(err)) - } - - adapter := &gcppubsub.Adapter{ - ProjectID: env.Project, - TopicID: env.Topic, - SinkURI: env.Sink, - SubscriptionID: env.Subscription, - TransformerURI: env.Transformer, - } - - logger.Info("Starting GCP Pub/Sub Receive Adapter. %v", zap.Reflect("adapter", adapter)) - if err := adapter.Start(ctx); err != nil { - logger.Fatal("failed to start adapter: ", zap.Error(err)) - } -} diff --git a/gcppubsub/config/100-namespace.yaml b/gcppubsub/config/100-namespace.yaml deleted file mode 100644 index 191577e146..0000000000 --- a/gcppubsub/config/100-namespace.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: v1 -kind: Namespace -metadata: - name: knative-sources - labels: - contrib.eventing.knative.dev/release: devel diff --git a/gcppubsub/config/200-serviceaccount.yaml b/gcppubsub/config/200-serviceaccount.yaml deleted file mode 100644 index c503336387..0000000000 --- a/gcppubsub/config/200-serviceaccount.yaml +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: v1 -kind: ServiceAccount -metadata: - name: gcppubsub-controller-manager - namespace: knative-sources - labels: - contrib.eventing.knative.dev/release: devel -secrets: -- name: gcppubsub-source-key ---- -apiVersion: v1 -kind: Secret -metadata: - name: gcppubsub-source-key - labels: - contrib.eventing.knative.dev/release: devel -type: Opaque -data: - 'key.json': "" diff --git a/gcppubsub/config/201-clusterrole.yaml b/gcppubsub/config/201-clusterrole.yaml deleted file mode 100644 index af6b821820..0000000000 --- a/gcppubsub/config/201-clusterrole.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: eventing-sources-gcppubsub-controller - labels: - contrib.eventing.knative.dev/release: devel -rules: - -- apiGroups: - - sources.eventing.knative.dev - resources: - - gcppubsubsources - verbs: &everything - - get - - list - - watch - - create - - update - - patch - - delete - -- apiGroups: - - sources.eventing.knative.dev - resources: - - gcppubsubsources/status - verbs: - - get - - update - - patch - -- apiGroups: - - apps - resources: - - deployments - verbs: *everything - -- apiGroups: - - "" - resources: - - secrets - verbs: &readOnly - - get - - list - - watch - -- apiGroups: - - eventing.knative.dev - resources: - - eventtypes - verbs: *everything diff --git a/gcppubsub/config/202-clusterrolebinding.yaml b/gcppubsub/config/202-clusterrolebinding.yaml deleted file mode 100644 index 6d78b1296d..0000000000 --- a/gcppubsub/config/202-clusterrolebinding.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: eventing-sources-gcppubsub-controller - labels: - contrib.eventing.knative.dev/release: devel -subjects: -- kind: ServiceAccount - name: gcppubsub-controller-manager - namespace: knative-sources -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: eventing-sources-gcppubsub-controller - ---- - -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: eventing-sources-gcppubsub-resolver - labels: - contrib.eventing.knative.dev/release: devel -subjects: -- kind: ServiceAccount - name: gcppubsub-controller-manager - namespace: knative-sources -# An aggregated ClusterRole for all Addressable CRDs. -# Ref: https://knative.dev/eventing/blob/master/config/200-addressable-resolvers-clusterrole.yaml -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: addressable-resolver diff --git a/gcppubsub/config/300-gcppubsubsource.yaml b/gcppubsub/config/300-gcppubsubsource.yaml deleted file mode 100644 index c5ff3010b8..0000000000 --- a/gcppubsub/config/300-gcppubsubsource.yaml +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - labels: - contrib.eventing.knative.dev/release: devel - eventing.knative.dev/source: "true" - knative.dev/crd-install: "true" - name: gcppubsubsources.sources.eventing.knative.dev -spec: - group: sources.eventing.knative.dev - names: - categories: - - all - - knative - - eventing - - sources - kind: GcpPubSubSource - plural: gcppubsubsources - scope: Namespaced - subresources: - status: {} - validation: - openAPIV3Schema: - properties: - registry: - type: object - description: "Internal information, users should not set this property" - properties: - eventTypes: - type: object - description: "Event types that GcpPubSubSource can produce" - properties: - event: - type: object - properties: - type: - type: string - pattern: "google.pubsub.topic.publish" - # TODO: set the schema pattern. - schema: - type: string - spec: - properties: - gcpCredsSecret: - type: object - description: "Credential to use to poll the GCP PubSub Subscription. It is not used to create or delete the Subscription, only to poll it. The value of the secret entry must be a service account key in the JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys)." - googleCloudProject: - type: string - description: "ID of the Google Cloud Project that the PubSub Topic exists in. E.g. 'my-project-1234' rather than its display name, 'My Project' or its number '1234567890'." - serviceAccountName: - type: string - description: "Name of the Kubernetes ServiceAccount that is running the Receiver Adapter Pods." - sink: - type: object - description: "Reference to an object that will resolve to a domain name to use as the sink." - transformer: - type: object - description: "Reference to an object that will resolve to a domain name to use as the transformer." - topic: - type: string - description: "ID of the GCP PubSub Topic to Subscribe to. It must be in the form of the unique identifier within the project, not the entire name. E.g. it must be 'laconia', not 'projects/my-gcp-project/topics/laconia'." - type: object - status: - properties: - conditions: - items: - properties: - lastTransitionTime: - # we use a string in the stored object but a wrapper object - # at runtime. - type: string - message: - type: string - reason: - type: string - severity: - type: string - status: - type: string - type: - type: string - required: - - type - - status - type: object - type: array - sinkUri: - type: string - transformerUri: - type: string - type: object - version: v1alpha1 diff --git a/gcppubsub/config/400-controller-service.yaml b/gcppubsub/config/400-controller-service.yaml deleted file mode 100644 index 70932430c0..0000000000 --- a/gcppubsub/config/400-controller-service.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: v1 -kind: Service -metadata: - name: gcppubsub-controller - namespace: knative-sources - labels: - contrib.eventing.knative.dev/release: devel - control-plane: gcppubsub-controller-manager -spec: - selector: - control-plane: gcppubsub-controller-manager - ports: - - port: 443 diff --git a/gcppubsub/config/500-controller.yaml b/gcppubsub/config/500-controller.yaml deleted file mode 100644 index 42017d5fc1..0000000000 --- a/gcppubsub/config/500-controller.yaml +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright 2019 The Knative 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. - -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: gcppubsub-controller-manager - namespace: knative-sources - labels: - contrib.eventing.knative.dev/release: devel - control-plane: gcppubsub-controller-manager -spec: - selector: - matchLabels: &labels - control-plane: gcppubsub-controller-manager - serviceName: gcppubsub-controller-manager - template: - metadata: - labels: *labels - spec: - serviceAccountName: gcppubsub-controller-manager - containers: - - name: manager - image: knative.dev/eventing-contrib/gcppubsub/cmd/controller - env: - - name: GOOGLE_APPLICATION_CREDENTIALS - value: /var/secrets/google/key.json - - name: GCPPUBSUB_RA_IMAGE - value: knative.dev/eventing-contrib/gcppubsub/cmd/receive_adapter - volumeMounts: - - name: google-cloud-key - mountPath: /var/secrets/google - resources: - limits: - cpu: 100m - memory: 30Mi - requests: - cpu: 20m - memory: 20Mi - volumes: - - name: google-cloud-key - secret: - secretName: gcppubsub-source-key - serviceAccount: gcppubsub-controller-manager - terminationGracePeriodSeconds: 10 diff --git a/gcppubsub/config/600-istioegress.yaml b/gcppubsub/config/600-istioegress.yaml deleted file mode 100644 index c07b93a342..0000000000 --- a/gcppubsub/config/600-istioegress.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2019 The Knative 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. - -# Needed by the GCP PubSub Source to communicate with GCP PubSub. -apiVersion: networking.istio.io/v1alpha3 -kind: ServiceEntry -metadata: - name: gcppubsub-bus-ext - labels: - contrib.eventing.knative.dev/release: devel -spec: - hosts: - - "*.googleapis.com" - - "accounts.google.com" - ports: - - number: 443 - name: https - protocol: HTTPS - location: MESH_EXTERNAL diff --git a/gcppubsub/pkg/adapter/adapter.go b/gcppubsub/pkg/adapter/adapter.go deleted file mode 100644 index 96fada65c2..0000000000 --- a/gcppubsub/pkg/adapter/adapter.go +++ /dev/null @@ -1,135 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "fmt" - - cloudevents "github.com/cloudevents/sdk-go" - "go.uber.org/zap" - "knative.dev/pkg/logging" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - "knative.dev/eventing-contrib/pkg/kncloudevents" - - // Imports the Google Cloud Pub/Sub client package. - "cloud.google.com/go/pubsub" - "golang.org/x/net/context" -) - -// Adapter implements the GCP Pub/Sub adapter to deliver Pub/Sub messages from -// a pre-existing topic/subscription to a Sink. -type Adapter struct { - // ProjectID is the pre-existing gcp project id to use. - ProjectID string - // TopicID is the pre-existing gcp pub/sub topic id to use. - TopicID string - // SubscriptionID is the pre-existing gcp pub/sub subscription id to use. - SubscriptionID string - // SinkURI is the URI messages will be forwarded on to. - SinkURI string - // TransformerURI is the URI messages will be forwarded on to for any transformation - // before they are sent to SinkURI. - TransformerURI string - - source string - client *pubsub.Client - subscription *pubsub.Subscription - - ceClient cloudevents.Client - - transformer bool - transformerClient cloudevents.Client -} - -func (a *Adapter) Start(ctx context.Context) error { - a.source = v1alpha1.GcpPubSubEventSource(a.ProjectID, a.TopicID) - - var err error - // Make the client to pubsub - if a.client, err = pubsub.NewClient(ctx, a.ProjectID); err != nil { - return err - } - - if a.ceClient == nil { - if a.ceClient, err = kncloudevents.NewDefaultClient(a.SinkURI); err != nil { - return fmt.Errorf("failed to create cloudevent client: %s", err.Error()) - } - } - - // Make the transformer client in case the TransformerURI has been set. - if a.TransformerURI != "" { - a.transformer = true - if a.transformerClient == nil { - if a.transformerClient, err = kncloudevents.NewDefaultClient(a.TransformerURI); err != nil { - return fmt.Errorf("failed to create transformer client: %s", err.Error()) - } - } - } - - // Set the subscription from the client - a.subscription = a.client.Subscription(a.SubscriptionID) - - // Using that subscription, start receiving messages. - // Note: subscription.Receive is a blocking call. - return a.subscription.Receive(ctx, func(ctx context.Context, m *pubsub.Message) { - a.receiveMessage(ctx, &PubSubMessageWrapper{M: m}) - }) -} - -func (a *Adapter) receiveMessage(ctx context.Context, m PubSubMessage) { - logger := logging.FromContext(ctx).With(zap.Any("eventID", m.ID()), zap.Any("sink", a.SinkURI)) - - logger.Debugw("Received message", zap.Any("messageData", m.Data())) - - err := a.postMessage(ctx, logger, m) - if err != nil { - logger.Infof("Failed to post message: %s", err) - m.Nack() - } else { - logger.Debug("Message sent successfully") - m.Ack() - } -} -func (a *Adapter) postMessage(ctx context.Context, logger *zap.SugaredLogger, m PubSubMessage) error { - // Create the CloudEvent. - event := cloudevents.NewEvent(cloudevents.VersionV02) - event.SetID(m.ID()) - event.SetTime(m.PublishTime()) - event.SetDataContentType(*cloudevents.StringOfApplicationJSON()) - event.SetSource(a.source) - event.SetData(m.Message()) - event.SetType(v1alpha1.GcpPubSubSourceEventType) - - // If a transformer has been configured, then transform the message. - if a.transformer { - resp, err := a.transformerClient.Send(ctx, event) - if err != nil { - logger.Errorf("error transforming cloud event %q", event.ID()) - return err - } - if resp == nil { - logger.Warnf("cloud event %q was not transformed", event.ID()) - return nil - } - // Update the event with the transformed one. - event = *resp - } - - _, err := a.ceClient.Send(ctx, event) - return err // err could be nil or an error -} diff --git a/gcppubsub/pkg/adapter/adapter_test.go b/gcppubsub/pkg/adapter/adapter_test.go deleted file mode 100644 index 2a4041d3ae..0000000000 --- a/gcppubsub/pkg/adapter/adapter_test.go +++ /dev/null @@ -1,234 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "context" - "encoding/json" - "io/ioutil" - "net/http" - "net/http/httptest" - "testing" - - "cloud.google.com/go/pubsub" - "github.com/cloudevents/sdk-go/pkg/cloudevents/client" - "go.uber.org/zap" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - "knative.dev/eventing-contrib/pkg/kncloudevents" -) - -func TestPostMessage_ServeHTTP(t *testing.T) { - testCases := map[string]struct { - sink func(http.ResponseWriter, *http.Request) - transformer func(http.ResponseWriter, *http.Request) - reqBody string - respBody string - attributes map[string]string - expectedEventType string - error bool - }{ - "happy": { - sink: accepted, - reqBody: `{"ID":"ABC","Data":"eyJrZXkiOiJ2YWx1ZSJ9","Attributes":null,"PublishTime":"0001-01-01T00:00:00Z"}`, - }, - "rejected": { - sink: rejected, - reqBody: `{"ID":"ABC","Data":"eyJrZXkiOiJ2YWx1ZSJ9","Attributes":null,"PublishTime":"0001-01-01T00:00:00Z"}`, - error: true, - }, - "happy with transformer": { - sink: accepted, - transformer: accepted, - reqBody: `{"ID":"ABC","Data":"eyJrZXkiOiJ2YWx1ZSJ9","Attributes":null,"PublishTime":"0001-01-01T00:00:00Z"}`, - }, - "rejected transformer": { - sink: accepted, - transformer: rejected, - reqBody: `{"ID":"ABC","Data":"eyJrZXkiOiJ2YWx1ZSJ9","Attributes":null,"PublishTime":"0001-01-01T00:00:00Z"}`, - error: true, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - sh := &fakeHandler{ - handler: tc.sink, - } - sinkServer := httptest.NewServer(sh) - defer sinkServer.Close() - - transformerURI := "" - var th *fakeHandler - var transformerServer *httptest.Server - if tc.transformer != nil { - th = &fakeHandler{ - handler: tc.transformer, - } - transformerServer = httptest.NewServer(th) - defer transformerServer.Close() - transformerURI = transformerServer.URL - } - - a := &Adapter{ - SinkURI: sinkServer.URL, - TransformerURI: transformerURI, - source: "test", - ceClient: func() client.Client { - c, _ := kncloudevents.NewDefaultClient(sinkServer.URL) - return c - }(), - } - - if tc.transformer != nil { - a.transformer = true - a.transformerClient = func() client.Client { - c, _ := kncloudevents.NewDefaultClient(transformerURI) - return c - }() - } - - data, err := json.Marshal(map[string]string{"key": "value"}) - if err != nil { - t.Errorf("unexpected error, %v", err) - } - - m := &PubSubMockMessage{ - MockID: "ABC", - M: &pubsub.Message{ - ID: "ABC", - Data: data, - Attributes: tc.attributes, - }, - } - err = a.postMessage(context.TODO(), zap.S(), m) - - if tc.error && err == nil { - t.Errorf("expected error, but got %v", err) - } - - et := sh.header.Get("Ce-Type") // bad bad bad. - // If a transformer was configured, read its header. - if tc.transformer != nil { - et = th.header.Get("Ce-Type") - } - - expectedEventType := v1alpha1.GcpPubSubSourceEventType - if tc.expectedEventType != "" { - expectedEventType = tc.expectedEventType - } - - if et != expectedEventType { - t.Errorf("Expected eventtype %q, but got %q", tc.expectedEventType, et) - } - if tc.transformer != nil { - if tc.reqBody != string(th.body) { - t.Errorf("expected request body from transformer %q, but got %q", tc.reqBody, th.body) - } - } else if tc.reqBody != string(sh.body) { - t.Errorf("expected request body from sink %q, but got %q", tc.reqBody, sh.body) - } - }) - } -} - -func TestReceiveMessage_ServeHTTP(t *testing.T) { - testCases := map[string]struct { - sink func(http.ResponseWriter, *http.Request) - acked bool - }{ - "happy": { - sink: accepted, - acked: true, - }, - "rejected": { - sink: rejected, - acked: false, - }, - } - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - h := &fakeHandler{ - handler: tc.sink, - } - sinkServer := httptest.NewServer(h) - defer sinkServer.Close() - - a := &Adapter{ - SinkURI: sinkServer.URL, - source: "test", - ceClient: func() client.Client { - c, _ := kncloudevents.NewDefaultClient(sinkServer.URL) - return c - }(), - } - - data, err := json.Marshal(map[string]string{"key": "value"}) - if err != nil { - t.Errorf("unexpected error, %v", err) - } - - m := &PubSubMockMessage{ - MockID: "ABC", - M: &pubsub.Message{ - ID: "ABC", - Data: data, - }, - } - a.receiveMessage(context.TODO(), m) - - if tc.acked && m.Nacked { - t.Errorf("expected message to be acked, but was not.") - } - - if !tc.acked && m.Acked { - t.Errorf("expected message to be nacked, but was not.") - } - - if m.Acked == m.Nacked { - t.Errorf("Message has the same Ack and Nack status: %v", m.Acked) - } - }) - } -} - -type fakeHandler struct { - body []byte - header http.Header - - handler func(http.ResponseWriter, *http.Request) -} - -func (h *fakeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - h.header = r.Header - body, err := ioutil.ReadAll(r.Body) - if err != nil { - http.Error(w, "can not read body", http.StatusBadRequest) - return - } - h.body = body - - defer r.Body.Close() - h.handler(w, r) -} - -func accepted(writer http.ResponseWriter, req *http.Request) { - writer.WriteHeader(http.StatusOK) -} - -func rejected(writer http.ResponseWriter, _ *http.Request) { - writer.WriteHeader(http.StatusRequestTimeout) -} diff --git a/gcppubsub/pkg/adapter/pubsub.go b/gcppubsub/pkg/adapter/pubsub.go deleted file mode 100644 index 2f1380d5e5..0000000000 --- a/gcppubsub/pkg/adapter/pubsub.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "time" - - // Imports the Google Cloud Pub/Sub client package. - "cloud.google.com/go/pubsub" -) - -type PubSubMessage interface { - Ack() - Nack() - ID() string - PublishTime() time.Time - Data() []byte - - Message() *pubsub.Message -} - -type PubSubMessageWrapper struct { - M *pubsub.Message -} - -func (w *PubSubMessageWrapper) Ack() { - w.M.Ack() -} - -func (w *PubSubMessageWrapper) Nack() { - w.M.Nack() -} - -func (w *PubSubMessageWrapper) Data() []byte { - return w.M.Data -} - -func (w *PubSubMessageWrapper) Message() *pubsub.Message { - return w.M -} - -func (w *PubSubMessageWrapper) ID() string { - return w.M.ID -} - -func (w *PubSubMessageWrapper) PublishTime() time.Time { - return w.M.PublishTime -} diff --git a/gcppubsub/pkg/adapter/pubsub_test.go b/gcppubsub/pkg/adapter/pubsub_test.go deleted file mode 100644 index 074cade3a8..0000000000 --- a/gcppubsub/pkg/adapter/pubsub_test.go +++ /dev/null @@ -1,93 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "encoding/json" - "testing" - "time" - - // Imports the Google Cloud Pub/Sub client package. - "cloud.google.com/go/pubsub" -) - -type PubSubMockMessage struct { - MockID string - MockPublishTime time.Time - MockData []byte - - Acked bool - Nacked bool - - M *pubsub.Message -} - -func (t *PubSubMockMessage) Ack() { - t.Acked = true -} - -func (t *PubSubMockMessage) Nack() { - t.Nacked = true -} - -func (t *PubSubMockMessage) Data() []byte { - return t.MockData -} - -func (t *PubSubMockMessage) Message() *pubsub.Message { - return t.M -} - -func (t *PubSubMockMessage) ID() string { - return t.MockID -} - -func (t *PubSubMockMessage) PublishTime() time.Time { - return t.MockPublishTime -} - -func TestPubSubMessageWrapper(t *testing.T) { - data, err := json.Marshal(map[string]string{"key": "value"}) - if err != nil { - t.Errorf("unexpected error, %v", err) - } - now := time.Now() - - m := &PubSubMessageWrapper{ - M: &pubsub.Message{ - ID: "ABC", - Data: data, - PublishTime: now, - }, - } - - if m.ID() != "ABC" { - t.Errorf("expected ID to be %s, got %s", "ABC", m.ID()) - } - - if m.PublishTime() != now { - t.Errorf("expected PublishTime to be %v, got %v", now, m.PublishTime()) - } - - if string(m.Data()) != string(data) { - t.Errorf("expected Data to be %v, got %v", string(data), m.Data()) - } - - if m.Message() != m.M { - t.Errorf("expected Message to be %v, got %v", m.M, m.Message()) - } -} diff --git a/gcppubsub/pkg/apis/addtoscheme_eventing_v1alpha1.go b/gcppubsub/pkg/apis/addtoscheme_eventing_v1alpha1.go deleted file mode 100644 index fcd491ba5f..0000000000 --- a/gcppubsub/pkg/apis/addtoscheme_eventing_v1alpha1.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -Copyright 2019 The Knative 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 apis - -import ( - eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" -) - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, eventingv1alpha1.SchemeBuilder.AddToScheme) -} diff --git a/gcppubsub/pkg/apis/addtoscheme_sources_v1alpha1.go b/gcppubsub/pkg/apis/addtoscheme_sources_v1alpha1.go deleted file mode 100644 index 0bd4280e7e..0000000000 --- a/gcppubsub/pkg/apis/addtoscheme_sources_v1alpha1.go +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright 2018 The Knative 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 apis - -import "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - -func init() { - // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) -} diff --git a/gcppubsub/pkg/apis/apis.go b/gcppubsub/pkg/apis/apis.go deleted file mode 100644 index c5a3afecab..0000000000 --- a/gcppubsub/pkg/apis/apis.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2018 The Knative 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. -*/ - -// Generate deepcopy for apis -//go:generate go run ../../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../../hack/boilerplate.go.txt - -// Package apis contains Kubernetes API groups. -package apis - -import ( - "k8s.io/apimachinery/pkg/runtime" -) - -// AddToSchemes may be used to add all resources defined in the project to a Scheme -var AddToSchemes runtime.SchemeBuilder - -// AddToScheme adds all Resources to the Scheme -func AddToScheme(s *runtime.Scheme) error { - return AddToSchemes.AddToScheme(s) -} diff --git a/gcppubsub/pkg/apis/sources/group.go b/gcppubsub/pkg/apis/sources/group.go deleted file mode 100644 index 78a2f748da..0000000000 --- a/gcppubsub/pkg/apis/sources/group.go +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2018 The Knative 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 sources contains sources API versions -package sources diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/doc.go b/gcppubsub/pkg/apis/sources/v1alpha1/doc.go deleted file mode 100644 index 9048a3a428..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/doc.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 contains API Schema definitions for the sources v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=knative.dev/eventing-contrib/pkg/apis/sources -// +k8s:defaulter-gen=TypeMeta -// +groupName=sources.eventing.knative.dev -package v1alpha1 diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types.go b/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types.go deleted file mode 100644 index 6bee29bd76..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types.go +++ /dev/null @@ -1,220 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 - -import ( - "fmt" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "knative.dev/pkg/apis" - "knative.dev/pkg/apis/duck" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// GcpPubSubSource is the Schema for the gcppubsubsources API. -// +k8s:openapi-gen=true -// +kubebuilder:subresource:status -// +kubebuilder:categories=all,knative,eventing,sources -type GcpPubSubSource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec GcpPubSubSourceSpec `json:"spec,omitempty"` - Status GcpPubSubSourceStatus `json:"status,omitempty"` -} - -// Check that GcpPubSubSource can be validated and can be defaulted. -var _ runtime.Object = (*GcpPubSubSource)(nil) - -// Check that GcpPubSubSource will be checked for immutable fields. -var _ apis.Immutable = (*GcpPubSubSource)(nil) - -// Check that GcpPubSubSource implements the Conditions duck type. -var _ = duck.VerifyType(&GcpPubSubSource{}, &duckv1alpha1.Conditions{}) - -// GcpPubSubSourceSpec defines the desired state of the GcpPubSubSource. -type GcpPubSubSourceSpec struct { - // GcpCredsSecret is the credential to use to poll the GCP PubSub Subscription. It is not used - // to create or delete the Subscription, only to poll it. The value of the secret entry must be - // a service account key in the JSON format - // ( see https://cloud.google.com/iam/docs/creating-managing-service-account-keys ). - GcpCredsSecret corev1.SecretKeySelector `json:"gcpCredsSecret,omitempty"` - - // GoogleCloudProject is the ID of the Google Cloud Project that the PubSub Topic exists in. - GoogleCloudProject string `json:"googleCloudProject,omitempty"` - - // Topic is the ID of the GCP PubSub Topic to Subscribe to. It must be in the form of the - // unique identifier within the project, not the entire name. E.g. it must be 'laconia', not - // 'projects/my-gcp-project/topics/laconia'. - Topic string `json:"topic,omitempty"` - - // Sink is a reference to an object that will resolve to a domain name to use as the sink. - // +optional - Sink *corev1.ObjectReference `json:"sink,omitempty"` - - // Transformer is a reference to an object that will resolve to a domain name to use as the transformer. - // +optional - Transformer *corev1.ObjectReference `json:"transformer,omitempty"` - - // ServiceAccoutName is the name of the ServiceAccount that will be used to run the Receive - // Adapter Deployment. - ServiceAccountName string `json:"serviceAccountName,omitempty"` -} - -const ( - // GcpPubSubSourceEventType is the GcpPubSub CloudEvent type, in case PubSub doesn't send a - // CloudEvent itself. - GcpPubSubSourceEventType = "google.pubsub.topic.publish" -) - -// GcpPubSubEventSource returns the GcpPubSub CloudEvent source value. -func GcpPubSubEventSource(googleCloudProject, topic string) string { - return fmt.Sprintf("//pubsub.googleapis.com/%s/topics/%s", googleCloudProject, topic) -} - -const ( - // GcpPubSubConditionReady has status True when the GcpPubSubSource is ready to send events. - GcpPubSubConditionReady = duckv1alpha1.ConditionReady - - // GcpPubSubConditionSinkProvided has status True when the GcpPubSubSource has been configured with a sink target. - GcpPubSubConditionSinkProvided duckv1alpha1.ConditionType = "SinkProvided" - - // GcpPubSubConditionTransformerProvided has status True when the GcpPubSubSource has been configured with a transformer target. - GcpPubSubConditionTransformerProvided duckv1alpha1.ConditionType = "TransformerProvided" - - // GcpPubSubConditionDeployed has status True when the GcpPubSubSource has had it's receive adapter deployment created. - GcpPubSubConditionDeployed duckv1alpha1.ConditionType = "Deployed" - - // GcpPubSubConditionSubscribed has status True when a GCP PubSub Subscription has been created pointing at the created receive adapter deployment. - GcpPubSubConditionSubscribed duckv1alpha1.ConditionType = "Subscribed" - - // GcpPubSubConditionEventTypesProvided has status True when the GcpPubSubSource has been configured with event types. - GcpPubSubConditionEventTypesProvided duckv1alpha1.ConditionType = "EventTypesProvided" -) - -var gcpPubSubSourceCondSet = duckv1alpha1.NewLivingConditionSet( - GcpPubSubConditionSinkProvided, - GcpPubSubConditionDeployed, - GcpPubSubConditionSubscribed) - -// GcpPubSubSourceStatus defines the observed state of GcpPubSubSource. -type GcpPubSubSourceStatus struct { - // inherits duck/v1alpha1 Status, which currently provides: - // * ObservedGeneration - the 'Generation' of the Service that was last processed by the controller. - // * Conditions - the latest available observations of a resource's current state. - duckv1alpha1.Status `json:",inline"` - - // SinkURI is the current active sink URI that has been configured for the GcpPubSubSource. - // +optional - SinkURI string `json:"sinkUri,omitempty"` - - // TransformerURI is the current active transformer URI that has been configured for the GcpPubSubSource. - // +optional - TransformerURI string `json:"transformerUri,omitempty"` -} - -// GetCondition returns the condition currently associated with the given type, or nil. -func (s *GcpPubSubSourceStatus) GetCondition(t duckv1alpha1.ConditionType) *duckv1alpha1.Condition { - return gcpPubSubSourceCondSet.Manage(s).GetCondition(t) -} - -// IsReady returns true if the resource is ready overall. -func (s *GcpPubSubSourceStatus) IsReady() bool { - return gcpPubSubSourceCondSet.Manage(s).IsHappy() -} - -// InitializeConditions sets relevant unset conditions to Unknown state. -func (s *GcpPubSubSourceStatus) InitializeConditions() { - gcpPubSubSourceCondSet.Manage(s).InitializeConditions() -} - -// MarkSink sets the condition that the source has a sink configured. -func (s *GcpPubSubSourceStatus) MarkSink(uri string) { - s.SinkURI = uri - if len(uri) > 0 { - gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionSinkProvided) - } else { - gcpPubSubSourceCondSet.Manage(s).MarkUnknown(GcpPubSubConditionSinkProvided, "SinkEmpty", "Sink has resolved to empty.") - } -} - -// MarkSink sets the condition that the source has a transformer configured. -func (s *GcpPubSubSourceStatus) MarkTransformer(uri string) { - s.TransformerURI = uri - if len(uri) > 0 { - gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionTransformerProvided) - } else { - gcpPubSubSourceCondSet.Manage(s).MarkUnknown(GcpPubSubConditionTransformerProvided, "TransformerEmpty", "Transformer has resolved to empty.") - } -} - -// MarkNoSink sets the condition that the source does not have a sink configured. -func (s *GcpPubSubSourceStatus) MarkNoSink(reason, messageFormat string, messageA ...interface{}) { - gcpPubSubSourceCondSet.Manage(s).MarkFalse(GcpPubSubConditionSinkProvided, reason, messageFormat, messageA...) -} - -// MarkNoTransformer sets the condition that the source does not have a transformer configured. -func (s *GcpPubSubSourceStatus) MarkNoTransformer(reason, messageFormat string, messageA ...interface{}) { - gcpPubSubSourceCondSet.Manage(s).MarkFalse(GcpPubSubConditionTransformerProvided, reason, messageFormat, messageA...) -} - -// MarkDeployed sets the condition that the source has been deployed. -func (s *GcpPubSubSourceStatus) MarkDeployed() { - gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionDeployed) -} - -// MarkDeploying sets the condition that the source is deploying. -func (s *GcpPubSubSourceStatus) MarkDeploying(reason, messageFormat string, messageA ...interface{}) { - gcpPubSubSourceCondSet.Manage(s).MarkUnknown(GcpPubSubConditionDeployed, reason, messageFormat, messageA...) -} - -// MarkNotDeployed sets the condition that the source has not been deployed. -func (s *GcpPubSubSourceStatus) MarkNotDeployed(reason, messageFormat string, messageA ...interface{}) { - gcpPubSubSourceCondSet.Manage(s).MarkFalse(GcpPubSubConditionDeployed, reason, messageFormat, messageA...) -} - -func (s *GcpPubSubSourceStatus) MarkSubscribed() { - gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionSubscribed) -} - -// MarkEventTypes sets the condition that the source has created its event types. -func (s *GcpPubSubSourceStatus) MarkEventTypes() { - gcpPubSubSourceCondSet.Manage(s).MarkTrue(GcpPubSubConditionEventTypesProvided) -} - -// MarkNoEventTypes sets the condition that the source does not its event types configured. -func (s *GcpPubSubSourceStatus) MarkNoEventTypes(reason, messageFormat string, messageA ...interface{}) { - gcpPubSubSourceCondSet.Manage(s).MarkFalse(GcpPubSubConditionEventTypesProvided, reason, messageFormat, messageA...) -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// GcpPubSubSourceList contains a list of GcpPubSubSources. -type GcpPubSubSourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []GcpPubSubSource `json:"items"` -} - -func init() { - SchemeBuilder.Register(&GcpPubSubSource{}, &GcpPubSubSourceList{}) -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types_test.go b/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types_test.go deleted file mode 100644 index de15d85e47..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_types_test.go +++ /dev/null @@ -1,450 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - corev1 "k8s.io/api/core/v1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" -) - -func TestGcpPubSubSourceStatusIsReady(t *testing.T) { - tests := []struct { - name string - s *GcpPubSubSourceStatus - want bool - }{{ - name: "uninitialized", - s: &GcpPubSubSourceStatus{}, - want: false, - }, { - name: "initialized", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - return s - }(), - want: false, - }, { - name: "mark deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkDeployed() - return s - }(), - want: false, - }, { - name: "mark sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - return s - }(), - want: false, - }, { - name: "mark subscribed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSubscribed() - return s - }(), - want: false, - }, { - name: "mark event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkEventTypes() - return s - }(), - want: false, - }, { - name: "mark sink and deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - return s - }(), - want: false, - }, { - name: "mark sink and deployed and subscribed and event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - return s - }(), - want: true, - }, { - name: "mark sink and deployed and subscribed and event types, then no sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNoSink("Testing", "") - return s - }(), - want: false, - }, { - name: "mark sink and deployed and subscribed and event types then deploying", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkDeploying("Testing", "") - return s - }(), - want: false, - }, { - name: "mark sink and deployed and subscribed and event types then not deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNotDeployed("Testing", "") - return s - }(), - want: false, - }, { - name: "mark sink and deployed and subscribed and event types then no event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNoEventTypes("Testing", "") - return s - }(), - want: true, - }, { - name: "mark sink and subscribed and not deployed then deploying then deployed then event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkSubscribed() - s.MarkNotDeployed("MarkNotDeployed", "") - s.MarkDeploying("MarkDeploying", "") - s.MarkDeployed() - s.MarkEventTypes() - return s - }(), - want: true, - }, { - name: "mark sink empty and deployed and subscribed and event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - return s - }(), - want: false, - }, { - name: "mark sink empty and deployed and subscribed and event types then sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkSink("uri://example") - return s - }(), - want: true, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.IsReady() - if diff := cmp.Diff(test.want, got); diff != "" { - t.Errorf("%s: unexpected condition (-want, +got) = %v", test.name, diff) - } - }) - } -} - -func TestGcpPubSubSourceStatusGetCondition(t *testing.T) { - tests := []struct { - name string - s *GcpPubSubSourceStatus - condQuery duckv1alpha1.ConditionType - want *duckv1alpha1.Condition - }{{ - name: "uninitialized", - s: &GcpPubSubSourceStatus{}, - condQuery: GcpPubSubConditionReady, - want: nil, - }, { - name: "initialized", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkDeployed() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark subscribed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSubscribed() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkEventTypes() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark sink and deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - }, - }, { - name: "mark sink and deployed and subscribed and event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark sink and deployed and subscribed and event types then no sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNoSink("Testing", "hi%s", "") - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionFalse, - Reason: "Testing", - Message: "hi", - }, - }, { - name: "mark sink and deployed and subscribed and event types then deploying", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkDeploying("Testing", "hi%s", "") - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - Reason: "Testing", - Message: "hi", - }, - }, { - name: "mark sink and deployed and subscribed and event types then not deployed", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNotDeployed("Testing", "hi%s", "") - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionFalse, - Reason: "Testing", - Message: "hi", - }, - }, { - name: "mark sink and deployed and subscribed and event types then no event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - s.MarkNoEventTypes("Testing", "hi%s", "") - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark sink and subscribed and not deployed then deploying then deployed then event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("uri://example") - s.MarkSubscribed() - s.MarkNotDeployed("MarkNotDeployed", "%s", "") - s.MarkDeploying("MarkDeploying", "%s", "") - s.MarkDeployed() - s.MarkEventTypes() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionTrue, - }, - }, { - name: "mark sink empty and deployed and subscribed and event types", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkEventTypes() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionUnknown, - Reason: "SinkEmpty", - Message: "Sink has resolved to empty.", - }, - }, { - name: "mark sink empty and deployed and subscribed and event types then sink", - s: func() *GcpPubSubSourceStatus { - s := &GcpPubSubSourceStatus{} - s.InitializeConditions() - s.MarkSink("") - s.MarkDeployed() - s.MarkSubscribed() - s.MarkSink("uri://example") - s.MarkEventTypes() - return s - }(), - condQuery: GcpPubSubConditionReady, - want: &duckv1alpha1.Condition{ - Type: GcpPubSubConditionReady, - Status: corev1.ConditionTrue, - }, - }} - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - got := test.s.GetCondition(test.condQuery) - ignoreTime := cmpopts.IgnoreFields(duckv1alpha1.Condition{}, - "LastTransitionTime", "Severity") - if diff := cmp.Diff(test.want, got, ignoreTime); diff != "" { - t.Errorf("unexpected condition (-want, +got) = %v", diff) - } - }) - } -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation.go b/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation.go deleted file mode 100644 index 359743bf3b..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 - -import ( - "context" - - "github.com/google/go-cmp/cmp" - "knative.dev/pkg/apis" -) - -func (current *GcpPubSubSource) CheckImmutableFields(ctx context.Context, og apis.Immutable) *apis.FieldError { - original, ok := og.(*GcpPubSubSource) - if !ok { - return &apis.FieldError{Message: "The provided original was not a GcpPubSubSource"} - } - if original == nil { - return nil - } - - // All of the fields are immutable because the controller doesn't understand when it would need - // to delete and create a new Receive Adapter with updated arguments. We could relax it slightly - // to allow a nil Sink -> non-nil Sink, but I don't think it is needed yet. - if diff := cmp.Diff(original.Spec, current.Spec); diff != "" { - return &apis.FieldError{ - Message: "Immutable fields changed (-old +new)", - Paths: []string{"spec"}, - Details: diff, - } - } - return nil -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation_test.go b/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation_test.go deleted file mode 100644 index 563a0ee9e2..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/gcp_pubsub_validation_test.go +++ /dev/null @@ -1,249 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 - -import ( - "context" - "testing" - - corev1 "k8s.io/api/core/v1" -) - -var ( - fullSpec = GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secret-name", - }, - Key: "secret-key", - }, - GoogleCloudProject: "my-gcp-project", - Topic: "pubsub-topic", - Sink: &corev1.ObjectReference{ - APIVersion: "foo", - Kind: "bar", - Namespace: "baz", - Name: "qux", - }, - ServiceAccountName: "service-account-name", - } -) - -func TestGcpPubSubSourceCheckImmutableFields(t *testing.T) { - testCases := map[string]struct { - orig *GcpPubSubSourceSpec - updated GcpPubSubSourceSpec - allowed bool - }{ - "nil orig": { - updated: fullSpec, - allowed: true, - }, - "GcpCredsSecret.Name changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "some-other-name", - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: fullSpec.Sink, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "GcpCredsSecret.Key changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: "some-other-key", - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: fullSpec.Sink, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "GoogleCloudProject changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: "some-other-project", - Topic: fullSpec.Topic, - Sink: fullSpec.Sink, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "Topic changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: "some-other-topic", - Sink: fullSpec.Sink, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "Sink.APIVersion changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: &corev1.ObjectReference{ - APIVersion: "some-other-api-version", - Kind: fullSpec.Sink.Kind, - Namespace: fullSpec.Sink.Namespace, - Name: fullSpec.Sink.Name, - }, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "Sink.Kind changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: &corev1.ObjectReference{ - APIVersion: fullSpec.Sink.APIVersion, - Kind: "some-other-kind", - Namespace: fullSpec.Sink.Namespace, - Name: fullSpec.Sink.Name, - }, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "Sink.Namespace changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: &corev1.ObjectReference{ - APIVersion: fullSpec.Sink.APIVersion, - Kind: fullSpec.Sink.Kind, - Namespace: "some-other-namespace", - Name: fullSpec.Sink.Name, - }, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "Sink.Name changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: &corev1.ObjectReference{ - APIVersion: fullSpec.Sink.APIVersion, - Kind: fullSpec.Sink.Kind, - Namespace: fullSpec.Sink.Namespace, - Name: "some-other-name", - }, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "ServiceAccountName changed": { - orig: &fullSpec, - updated: GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: fullSpec.GcpCredsSecret.Name, - }, - Key: fullSpec.GcpCredsSecret.Key, - }, - GoogleCloudProject: fullSpec.GoogleCloudProject, - Topic: fullSpec.Topic, - Sink: &corev1.ObjectReference{ - APIVersion: fullSpec.Sink.APIVersion, - Kind: fullSpec.Sink.Kind, - Namespace: fullSpec.Sink.Namespace, - Name: "some-other-name", - }, - ServiceAccountName: fullSpec.ServiceAccountName, - }, - allowed: false, - }, - "no change": { - orig: &fullSpec, - updated: fullSpec, - allowed: true, - }, - } - - for n, tc := range testCases { - t.Run(n, func(t *testing.T) { - var orig *GcpPubSubSource - if tc.orig != nil { - orig = &GcpPubSubSource{ - Spec: *tc.orig, - } - } - updated := &GcpPubSubSource{ - Spec: tc.updated, - } - err := updated.CheckImmutableFields(context.TODO(), orig) - if tc.allowed != (err == nil) { - t.Fatalf("Unexpected immutable field check. Expected %v. Actual %v", tc.allowed, err) - } - }) - } -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/register.go b/gcppubsub/pkg/apis/sources/v1alpha1/register.go deleted file mode 100644 index 9a0d7770b0..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/register.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2018 The Knative 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. -*/ - -// NOTE: Boilerplate only. Ignore this file. - -// Package v1alpha1 contains API Schema definitions for the sources v1alpha1 API group -// +k8s:openapi-gen=true -// +k8s:deepcopy-gen=package,register -// +k8s:conversion-gen=knative.dev/eventing-contrib/pkg/apis/sources -// +k8s:defaulter-gen=TypeMeta -// +groupName=sources.eventing.knative.dev -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" -) - -var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "sources.eventing.knative.dev", Version: "v1alpha1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} - - AddToScheme = SchemeBuilder.AddToScheme -) - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/register_test.go b/gcppubsub/pkg/apis/sources/v1alpha1/register_test.go deleted file mode 100644 index 4d700b083b..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/register_test.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -Copyright 2018 The Knative 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 v1alpha1 - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func TestResource(t *testing.T) { - want := schema.GroupResource{ - Group: "sources.eventing.knative.dev", - Resource: "foo", - } - - got := Resource("foo") - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected resource (-want, +got) = %v", diff) - } -} diff --git a/gcppubsub/pkg/apis/sources/v1alpha1/zz_generated.deepcopy.go b/gcppubsub/pkg/apis/sources/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index fa41a8f350..0000000000 --- a/gcppubsub/pkg/apis/sources/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,131 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1 "k8s.io/api/core/v1" - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GcpPubSubSource) DeepCopyInto(out *GcpPubSubSource) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GcpPubSubSource. -func (in *GcpPubSubSource) DeepCopy() *GcpPubSubSource { - if in == nil { - return nil - } - out := new(GcpPubSubSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GcpPubSubSource) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GcpPubSubSourceList) DeepCopyInto(out *GcpPubSubSourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - out.ListMeta = in.ListMeta - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]GcpPubSubSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GcpPubSubSourceList. -func (in *GcpPubSubSourceList) DeepCopy() *GcpPubSubSourceList { - if in == nil { - return nil - } - out := new(GcpPubSubSourceList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GcpPubSubSourceList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GcpPubSubSourceSpec) DeepCopyInto(out *GcpPubSubSourceSpec) { - *out = *in - in.GcpCredsSecret.DeepCopyInto(&out.GcpCredsSecret) - if in.Sink != nil { - in, out := &in.Sink, &out.Sink - *out = new(v1.ObjectReference) - **out = **in - } - if in.Transformer != nil { - in, out := &in.Transformer, &out.Transformer - *out = new(v1.ObjectReference) - **out = **in - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GcpPubSubSourceSpec. -func (in *GcpPubSubSourceSpec) DeepCopy() *GcpPubSubSourceSpec { - if in == nil { - return nil - } - out := new(GcpPubSubSourceSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GcpPubSubSourceStatus) DeepCopyInto(out *GcpPubSubSourceStatus) { - *out = *in - in.Status.DeepCopyInto(&out.Status) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GcpPubSubSourceStatus. -func (in *GcpPubSubSourceStatus) DeepCopy() *GcpPubSubSourceStatus { - if in == nil { - return nil - } - out := new(GcpPubSubSourceStatus) - in.DeepCopyInto(out) - return out -} diff --git a/gcppubsub/pkg/client/clientset/versioned/clientset.go b/gcppubsub/pkg/client/clientset/versioned/clientset.go deleted file mode 100644 index f75078f63b..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/clientset.go +++ /dev/null @@ -1,98 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package versioned - -import ( - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" - sourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1" -) - -type Interface interface { - Discovery() discovery.DiscoveryInterface - SourcesV1alpha1() sourcesv1alpha1.SourcesV1alpha1Interface - // Deprecated: please explicitly pick a version if possible. - Sources() sourcesv1alpha1.SourcesV1alpha1Interface -} - -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. -type Clientset struct { - *discovery.DiscoveryClient - sourcesV1alpha1 *sourcesv1alpha1.SourcesV1alpha1Client -} - -// SourcesV1alpha1 retrieves the SourcesV1alpha1Client -func (c *Clientset) SourcesV1alpha1() sourcesv1alpha1.SourcesV1alpha1Interface { - return c.sourcesV1alpha1 -} - -// Deprecated: Sources retrieves the default version of SourcesClient. -// Please explicitly pick a version. -func (c *Clientset) Sources() sourcesv1alpha1.SourcesV1alpha1Interface { - return c.sourcesV1alpha1 -} - -// Discovery retrieves the DiscoveryClient -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - if c == nil { - return nil - } - return c.DiscoveryClient -} - -// NewForConfig creates a new Clientset for the given config. -func NewForConfig(c *rest.Config) (*Clientset, error) { - configShallowCopy := *c - if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { - configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) - } - var cs Clientset - var err error - cs.sourcesV1alpha1, err = sourcesv1alpha1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } - - cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) - if err != nil { - return nil, err - } - return &cs, nil -} - -// NewForConfigOrDie creates a new Clientset for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *Clientset { - var cs Clientset - cs.sourcesV1alpha1 = sourcesv1alpha1.NewForConfigOrDie(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) - return &cs -} - -// New creates a new Clientset for the given RESTClient. -func New(c rest.Interface) *Clientset { - var cs Clientset - cs.sourcesV1alpha1 = sourcesv1alpha1.New(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClient(c) - return &cs -} diff --git a/gcppubsub/pkg/client/clientset/versioned/doc.go b/gcppubsub/pkg/client/clientset/versioned/doc.go deleted file mode 100644 index 1122e50bfc..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated clientset. -package versioned diff --git a/gcppubsub/pkg/client/clientset/versioned/fake/clientset_generated.go b/gcppubsub/pkg/client/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index 3820601aeb..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" - clientset "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned" - sourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1" - fakesourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake" -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *Clientset { - o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objects { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - cs := &Clientset{} - cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} - cs.AddReactor("*", "*", testing.ObjectReaction(o)) - cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { - gvr := action.GetResource() - ns := action.GetNamespace() - watch, err := o.Watch(gvr, ns) - if err != nil { - return false, nil, err - } - return true, watch, nil - }) - - return cs -} - -// Clientset implements clientset.Interface. Meant to be embedded into a -// struct to get a default implementation. This makes faking out just the method -// you want to test easier. -type Clientset struct { - testing.Fake - discovery *fakediscovery.FakeDiscovery -} - -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -var _ clientset.Interface = &Clientset{} - -// SourcesV1alpha1 retrieves the SourcesV1alpha1Client -func (c *Clientset) SourcesV1alpha1() sourcesv1alpha1.SourcesV1alpha1Interface { - return &fakesourcesv1alpha1.FakeSourcesV1alpha1{Fake: &c.Fake} -} - -// Sources retrieves the SourcesV1alpha1Client -func (c *Clientset) Sources() sourcesv1alpha1.SourcesV1alpha1Interface { - return &fakesourcesv1alpha1.FakeSourcesV1alpha1{Fake: &c.Fake} -} diff --git a/gcppubsub/pkg/client/clientset/versioned/fake/doc.go b/gcppubsub/pkg/client/clientset/versioned/fake/doc.go deleted file mode 100644 index 87f3c3e0b0..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated fake clientset. -package fake diff --git a/gcppubsub/pkg/client/clientset/versioned/fake/register.go b/gcppubsub/pkg/client/clientset/versioned/fake/register.go deleted file mode 100644 index 8c7f158ea6..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/fake/register.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - sourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -var scheme = runtime.NewScheme() -var codecs = serializer.NewCodecFactory(scheme) -var parameterCodec = runtime.NewParameterCodec(scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ - sourcesv1alpha1.AddToScheme, -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -var AddToScheme = localSchemeBuilder.AddToScheme - -func init() { - v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) - utilruntime.Must(AddToScheme(scheme)) -} diff --git a/gcppubsub/pkg/client/clientset/versioned/scheme/doc.go b/gcppubsub/pkg/client/clientset/versioned/scheme/doc.go deleted file mode 100644 index 7d76538485..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/gcppubsub/pkg/client/clientset/versioned/scheme/register.go b/gcppubsub/pkg/client/clientset/versioned/scheme/register.go deleted file mode 100644 index fcb8e77b68..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package scheme - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - sourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ - sourcesv1alpha1.AddToScheme, -} - -// AddToScheme adds all types of this clientset into the given scheme. This allows composition -// of clientsets, like in: -// -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) -// -// kclientset, _ := kubernetes.NewForConfig(c) -// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) -// -// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types -// correctly. -var AddToScheme = localSchemeBuilder.AddToScheme - -func init() { - v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) - utilruntime.Must(AddToScheme(Scheme)) -} diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/doc.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/doc.go deleted file mode 100644 index a1c6bb9fe8..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v1alpha1 diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/doc.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/doc.go deleted file mode 100644 index a00e5d7b21..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_gcppubsubsource.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_gcppubsubsource.go deleted file mode 100644 index fd95167636..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_gcppubsubsource.go +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -// FakeGcpPubSubSources implements GcpPubSubSourceInterface -type FakeGcpPubSubSources struct { - Fake *FakeSourcesV1alpha1 - ns string -} - -var gcppubsubsourcesResource = schema.GroupVersionResource{Group: "sources.eventing.knative.dev", Version: "v1alpha1", Resource: "gcppubsubsources"} - -var gcppubsubsourcesKind = schema.GroupVersionKind{Group: "sources.eventing.knative.dev", Version: "v1alpha1", Kind: "GcpPubSubSource"} - -// Get takes name of the gcpPubSubSource, and returns the corresponding gcpPubSubSource object, and an error if there is any. -func (c *FakeGcpPubSubSources) Get(name string, options v1.GetOptions) (result *v1alpha1.GcpPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(gcppubsubsourcesResource, c.ns, name), &v1alpha1.GcpPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.GcpPubSubSource), err -} - -// List takes label and field selectors, and returns the list of GcpPubSubSources that match those selectors. -func (c *FakeGcpPubSubSources) List(opts v1.ListOptions) (result *v1alpha1.GcpPubSubSourceList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(gcppubsubsourcesResource, gcppubsubsourcesKind, c.ns, opts), &v1alpha1.GcpPubSubSourceList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.GcpPubSubSourceList{ListMeta: obj.(*v1alpha1.GcpPubSubSourceList).ListMeta} - for _, item := range obj.(*v1alpha1.GcpPubSubSourceList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested gcpPubSubSources. -func (c *FakeGcpPubSubSources) Watch(opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(gcppubsubsourcesResource, c.ns, opts)) - -} - -// Create takes the representation of a gcpPubSubSource and creates it. Returns the server's representation of the gcpPubSubSource, and an error, if there is any. -func (c *FakeGcpPubSubSources) Create(gcpPubSubSource *v1alpha1.GcpPubSubSource) (result *v1alpha1.GcpPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(gcppubsubsourcesResource, c.ns, gcpPubSubSource), &v1alpha1.GcpPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.GcpPubSubSource), err -} - -// Update takes the representation of a gcpPubSubSource and updates it. Returns the server's representation of the gcpPubSubSource, and an error, if there is any. -func (c *FakeGcpPubSubSources) Update(gcpPubSubSource *v1alpha1.GcpPubSubSource) (result *v1alpha1.GcpPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(gcppubsubsourcesResource, c.ns, gcpPubSubSource), &v1alpha1.GcpPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.GcpPubSubSource), err -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeGcpPubSubSources) UpdateStatus(gcpPubSubSource *v1alpha1.GcpPubSubSource) (*v1alpha1.GcpPubSubSource, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(gcppubsubsourcesResource, "status", c.ns, gcpPubSubSource), &v1alpha1.GcpPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.GcpPubSubSource), err -} - -// Delete takes name of the gcpPubSubSource and deletes it. Returns an error if one occurs. -func (c *FakeGcpPubSubSources) Delete(name string, options *v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(gcppubsubsourcesResource, c.ns, name), &v1alpha1.GcpPubSubSource{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeGcpPubSubSources) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(gcppubsubsourcesResource, c.ns, listOptions) - - _, err := c.Fake.Invokes(action, &v1alpha1.GcpPubSubSourceList{}) - return err -} - -// Patch applies the patch and returns the patched gcpPubSubSource. -func (c *FakeGcpPubSubSources) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.GcpPubSubSource, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(gcppubsubsourcesResource, c.ns, name, data, subresources...), &v1alpha1.GcpPubSubSource{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.GcpPubSubSource), err -} diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_sources_client.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_sources_client.go deleted file mode 100644 index 30db4ee028..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/fake/fake_sources_client.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1" -) - -type FakeSourcesV1alpha1 struct { - *testing.Fake -} - -func (c *FakeSourcesV1alpha1) GcpPubSubSources(namespace string) v1alpha1.GcpPubSubSourceInterface { - return &FakeGcpPubSubSources{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeSourcesV1alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/gcppubsubsource.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/gcppubsubsource.go deleted file mode 100644 index a66632e72f..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/gcppubsubsource.go +++ /dev/null @@ -1,174 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - scheme "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/scheme" -) - -// GcpPubSubSourcesGetter has a method to return a GcpPubSubSourceInterface. -// A group's client should implement this interface. -type GcpPubSubSourcesGetter interface { - GcpPubSubSources(namespace string) GcpPubSubSourceInterface -} - -// GcpPubSubSourceInterface has methods to work with GcpPubSubSource resources. -type GcpPubSubSourceInterface interface { - Create(*v1alpha1.GcpPubSubSource) (*v1alpha1.GcpPubSubSource, error) - Update(*v1alpha1.GcpPubSubSource) (*v1alpha1.GcpPubSubSource, error) - UpdateStatus(*v1alpha1.GcpPubSubSource) (*v1alpha1.GcpPubSubSource, error) - Delete(name string, options *v1.DeleteOptions) error - DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error - Get(name string, options v1.GetOptions) (*v1alpha1.GcpPubSubSource, error) - List(opts v1.ListOptions) (*v1alpha1.GcpPubSubSourceList, error) - Watch(opts v1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.GcpPubSubSource, err error) - GcpPubSubSourceExpansion -} - -// gcpPubSubSources implements GcpPubSubSourceInterface -type gcpPubSubSources struct { - client rest.Interface - ns string -} - -// newGcpPubSubSources returns a GcpPubSubSources -func newGcpPubSubSources(c *SourcesV1alpha1Client, namespace string) *gcpPubSubSources { - return &gcpPubSubSources{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the gcpPubSubSource, and returns the corresponding gcpPubSubSource object, and an error if there is any. -func (c *gcpPubSubSources) Get(name string, options v1.GetOptions) (result *v1alpha1.GcpPubSubSource, err error) { - result = &v1alpha1.GcpPubSubSource{} - err = c.client.Get(). - Namespace(c.ns). - Resource("gcppubsubsources"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of GcpPubSubSources that match those selectors. -func (c *gcpPubSubSources) List(opts v1.ListOptions) (result *v1alpha1.GcpPubSubSourceList, err error) { - result = &v1alpha1.GcpPubSubSourceList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("gcppubsubsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Do(). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested gcpPubSubSources. -func (c *gcpPubSubSources) Watch(opts v1.ListOptions) (watch.Interface, error) { - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("gcppubsubsources"). - VersionedParams(&opts, scheme.ParameterCodec). - Watch() -} - -// Create takes the representation of a gcpPubSubSource and creates it. Returns the server's representation of the gcpPubSubSource, and an error, if there is any. -func (c *gcpPubSubSources) Create(gcpPubSubSource *v1alpha1.GcpPubSubSource) (result *v1alpha1.GcpPubSubSource, err error) { - result = &v1alpha1.GcpPubSubSource{} - err = c.client.Post(). - Namespace(c.ns). - Resource("gcppubsubsources"). - Body(gcpPubSubSource). - Do(). - Into(result) - return -} - -// Update takes the representation of a gcpPubSubSource and updates it. Returns the server's representation of the gcpPubSubSource, and an error, if there is any. -func (c *gcpPubSubSources) Update(gcpPubSubSource *v1alpha1.GcpPubSubSource) (result *v1alpha1.GcpPubSubSource, err error) { - result = &v1alpha1.GcpPubSubSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("gcppubsubsources"). - Name(gcpPubSubSource.Name). - Body(gcpPubSubSource). - Do(). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - -func (c *gcpPubSubSources) UpdateStatus(gcpPubSubSource *v1alpha1.GcpPubSubSource) (result *v1alpha1.GcpPubSubSource, err error) { - result = &v1alpha1.GcpPubSubSource{} - err = c.client.Put(). - Namespace(c.ns). - Resource("gcppubsubsources"). - Name(gcpPubSubSource.Name). - SubResource("status"). - Body(gcpPubSubSource). - Do(). - Into(result) - return -} - -// Delete takes name of the gcpPubSubSource and deletes it. Returns an error if one occurs. -func (c *gcpPubSubSources) Delete(name string, options *v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("gcppubsubsources"). - Name(name). - Body(options). - Do(). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *gcpPubSubSources) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("gcppubsubsources"). - VersionedParams(&listOptions, scheme.ParameterCodec). - Body(options). - Do(). - Error() -} - -// Patch applies the patch and returns the patched gcpPubSubSource. -func (c *gcpPubSubSources) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.GcpPubSubSource, err error) { - result = &v1alpha1.GcpPubSubSource{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("gcppubsubsources"). - SubResource(subresources...). - Name(name). - Body(data). - Do(). - Into(result) - return -} diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/generated_expansion.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/generated_expansion.go deleted file mode 100644 index f154b21d9c..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/generated_expansion.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -type GcpPubSubSourceExpansion interface{} diff --git a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/sources_client.go b/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/sources_client.go deleted file mode 100644 index 9339617d87..0000000000 --- a/gcppubsub/pkg/client/clientset/versioned/typed/sources/v1alpha1/sources_client.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - rest "k8s.io/client-go/rest" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned/scheme" -) - -type SourcesV1alpha1Interface interface { - RESTClient() rest.Interface - GcpPubSubSourcesGetter -} - -// SourcesV1alpha1Client is used to interact with features provided by the sources.eventing.knative.dev group. -type SourcesV1alpha1Client struct { - restClient rest.Interface -} - -func (c *SourcesV1alpha1Client) GcpPubSubSources(namespace string) GcpPubSubSourceInterface { - return newGcpPubSubSources(c, namespace) -} - -// NewForConfig creates a new SourcesV1alpha1Client for the given config. -func NewForConfig(c *rest.Config) (*SourcesV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientFor(&config) - if err != nil { - return nil, err - } - return &SourcesV1alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new SourcesV1alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *SourcesV1alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new SourcesV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *SourcesV1alpha1Client { - return &SourcesV1alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *SourcesV1alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/gcppubsub/pkg/client/informers/externalversions/factory.go b/gcppubsub/pkg/client/informers/externalversions/factory.go deleted file mode 100644 index 8c43117107..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/factory.go +++ /dev/null @@ -1,180 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package externalversions - -import ( - reflect "reflect" - sync "sync" - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" - versioned "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/internalinterfaces" - sources "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/sources" -) - -// SharedInformerOption defines the functional option type for SharedInformerFactory. -type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory - -type sharedInformerFactory struct { - client versioned.Interface - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc - lock sync.Mutex - defaultResync time.Duration - customResync map[reflect.Type]time.Duration - - informers map[reflect.Type]cache.SharedIndexInformer - // startedInformers is used for tracking which informers have been started. - // This allows Start() to be called multiple times safely. - startedInformers map[reflect.Type]bool -} - -// WithCustomResyncConfig sets a custom resync period for the specified informer types. -func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - for k, v := range resyncConfig { - factory.customResync[reflect.TypeOf(k)] = v - } - return factory - } -} - -// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. -func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.tweakListOptions = tweakListOptions - return factory - } -} - -// WithNamespace limits the SharedInformerFactory to the specified namespace. -func WithNamespace(namespace string) SharedInformerOption { - return func(factory *sharedInformerFactory) *sharedInformerFactory { - factory.namespace = namespace - return factory - } -} - -// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. -func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { - return NewSharedInformerFactoryWithOptions(client, defaultResync) -} - -// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. -// Listers obtained via this SharedInformerFactory will be subject to the same filters -// as specified here. -// Deprecated: Please use NewSharedInformerFactoryWithOptions instead -func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { - return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) -} - -// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. -func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { - factory := &sharedInformerFactory{ - client: client, - namespace: v1.NamespaceAll, - defaultResync: defaultResync, - informers: make(map[reflect.Type]cache.SharedIndexInformer), - startedInformers: make(map[reflect.Type]bool), - customResync: make(map[reflect.Type]time.Duration), - } - - // Apply all options - for _, opt := range options { - factory = opt(factory) - } - - return factory -} - -// Start initializes all requested informers. -func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { - f.lock.Lock() - defer f.lock.Unlock() - - for informerType, informer := range f.informers { - if !f.startedInformers[informerType] { - go informer.Run(stopCh) - f.startedInformers[informerType] = true - } - } -} - -// WaitForCacheSync waits for all started informers' cache were synced. -func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { - informers := func() map[reflect.Type]cache.SharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informers := map[reflect.Type]cache.SharedIndexInformer{} - for informerType, informer := range f.informers { - if f.startedInformers[informerType] { - informers[informerType] = informer - } - } - return informers - }() - - res := map[reflect.Type]bool{} - for informType, informer := range informers { - res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) - } - return res -} - -// InternalInformerFor returns the SharedIndexInformer for obj using an internal -// client. -func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { - f.lock.Lock() - defer f.lock.Unlock() - - informerType := reflect.TypeOf(obj) - informer, exists := f.informers[informerType] - if exists { - return informer - } - - resyncPeriod, exists := f.customResync[informerType] - if !exists { - resyncPeriod = f.defaultResync - } - - informer = newFunc(f.client, resyncPeriod) - f.informers[informerType] = informer - - return informer -} - -// SharedInformerFactory provides shared informers for resources in all known -// API group versions. -type SharedInformerFactory interface { - internalinterfaces.SharedInformerFactory - ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - - Sources() sources.Interface -} - -func (f *sharedInformerFactory) Sources() sources.Interface { - return sources.New(f, f.namespace, f.tweakListOptions) -} diff --git a/gcppubsub/pkg/client/informers/externalversions/generic.go b/gcppubsub/pkg/client/informers/externalversions/generic.go deleted file mode 100644 index d39407fb44..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/generic.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package externalversions - -import ( - "fmt" - - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -// GenericInformer is type of SharedIndexInformer which will locate and delegate to other -// sharedInformers based on type -type GenericInformer interface { - Informer() cache.SharedIndexInformer - Lister() cache.GenericLister -} - -type genericInformer struct { - informer cache.SharedIndexInformer - resource schema.GroupResource -} - -// Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer -} - -// Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) -} - -// ForResource gives generic access to a shared informer of the matching type -// TODO extend this to unknown resources with a client pool -func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { - switch resource { - // Group=sources.eventing.knative.dev, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("gcppubsubsources"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Sources().V1alpha1().GcpPubSubSources().Informer()}, nil - - } - - return nil, fmt.Errorf("no informer found for %v", resource) -} diff --git a/gcppubsub/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/gcppubsub/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go deleted file mode 100644 index a5b8204214..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package internalinterfaces - -import ( - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - cache "k8s.io/client-go/tools/cache" - versioned "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned" -) - -type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer - -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle -type SharedInformerFactory interface { - Start(stopCh <-chan struct{}) - InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer -} - -type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/gcppubsub/pkg/client/informers/externalversions/sources/interface.go b/gcppubsub/pkg/client/informers/externalversions/sources/interface.go deleted file mode 100644 index 1456426e61..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/sources/interface.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package sources - -import ( - internalinterfaces "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1" -) - -// Interface provides access to each of this group's versions. -type Interface interface { - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/gcppubsubsource.go b/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/gcppubsubsource.go deleted file mode 100644 index 089b388731..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/gcppubsubsource.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - sourcesv1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - versioned "knative.dev/eventing-contrib/gcppubsub/pkg/client/clientset/versioned" - internalinterfaces "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/client/listers/sources/v1alpha1" -) - -// GcpPubSubSourceInformer provides access to a shared informer and lister for -// GcpPubSubSources. -type GcpPubSubSourceInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.GcpPubSubSourceLister -} - -type gcpPubSubSourceInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewGcpPubSubSourceInformer constructs a new informer for GcpPubSubSource type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewGcpPubSubSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredGcpPubSubSourceInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredGcpPubSubSourceInformer constructs a new informer for GcpPubSubSource type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredGcpPubSubSourceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SourcesV1alpha1().GcpPubSubSources(namespace).List(options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SourcesV1alpha1().GcpPubSubSources(namespace).Watch(options) - }, - }, - &sourcesv1alpha1.GcpPubSubSource{}, - resyncPeriod, - indexers, - ) -} - -func (f *gcpPubSubSourceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredGcpPubSubSourceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *gcpPubSubSourceInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&sourcesv1alpha1.GcpPubSubSource{}, f.defaultInformer) -} - -func (f *gcpPubSubSourceInformer) Lister() v1alpha1.GcpPubSubSourceLister { - return v1alpha1.NewGcpPubSubSourceLister(f.Informer().GetIndexer()) -} diff --git a/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/interface.go b/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/interface.go deleted file mode 100644 index c6d64708a4..0000000000 --- a/gcppubsub/pkg/client/informers/externalversions/sources/v1alpha1/interface.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - internalinterfaces "knative.dev/eventing-contrib/gcppubsub/pkg/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // GcpPubSubSources returns a GcpPubSubSourceInformer. - GcpPubSubSources() GcpPubSubSourceInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// GcpPubSubSources returns a GcpPubSubSourceInformer. -func (v *version) GcpPubSubSources() GcpPubSubSourceInformer { - return &gcpPubSubSourceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/gcppubsub/pkg/client/listers/sources/v1alpha1/expansion_generated.go b/gcppubsub/pkg/client/listers/sources/v1alpha1/expansion_generated.go deleted file mode 100644 index 33bec3a372..0000000000 --- a/gcppubsub/pkg/client/listers/sources/v1alpha1/expansion_generated.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -// GcpPubSubSourceListerExpansion allows custom methods to be added to -// GcpPubSubSourceLister. -type GcpPubSubSourceListerExpansion interface{} - -// GcpPubSubSourceNamespaceListerExpansion allows custom methods to be added to -// GcpPubSubSourceNamespaceLister. -type GcpPubSubSourceNamespaceListerExpansion interface{} diff --git a/gcppubsub/pkg/client/listers/sources/v1alpha1/gcppubsubsource.go b/gcppubsub/pkg/client/listers/sources/v1alpha1/gcppubsubsource.go deleted file mode 100644 index 2cea291598..0000000000 --- a/gcppubsub/pkg/client/listers/sources/v1alpha1/gcppubsubsource.go +++ /dev/null @@ -1,94 +0,0 @@ -/* -Copyright 2019 The Knative 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -// GcpPubSubSourceLister helps list GcpPubSubSources. -type GcpPubSubSourceLister interface { - // List lists all GcpPubSubSources in the indexer. - List(selector labels.Selector) (ret []*v1alpha1.GcpPubSubSource, err error) - // GcpPubSubSources returns an object that can list and get GcpPubSubSources. - GcpPubSubSources(namespace string) GcpPubSubSourceNamespaceLister - GcpPubSubSourceListerExpansion -} - -// gcpPubSubSourceLister implements the GcpPubSubSourceLister interface. -type gcpPubSubSourceLister struct { - indexer cache.Indexer -} - -// NewGcpPubSubSourceLister returns a new GcpPubSubSourceLister. -func NewGcpPubSubSourceLister(indexer cache.Indexer) GcpPubSubSourceLister { - return &gcpPubSubSourceLister{indexer: indexer} -} - -// List lists all GcpPubSubSources in the indexer. -func (s *gcpPubSubSourceLister) List(selector labels.Selector) (ret []*v1alpha1.GcpPubSubSource, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.GcpPubSubSource)) - }) - return ret, err -} - -// GcpPubSubSources returns an object that can list and get GcpPubSubSources. -func (s *gcpPubSubSourceLister) GcpPubSubSources(namespace string) GcpPubSubSourceNamespaceLister { - return gcpPubSubSourceNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// GcpPubSubSourceNamespaceLister helps list and get GcpPubSubSources. -type GcpPubSubSourceNamespaceLister interface { - // List lists all GcpPubSubSources in the indexer for a given namespace. - List(selector labels.Selector) (ret []*v1alpha1.GcpPubSubSource, err error) - // Get retrieves the GcpPubSubSource from the indexer for a given namespace and name. - Get(name string) (*v1alpha1.GcpPubSubSource, error) - GcpPubSubSourceNamespaceListerExpansion -} - -// gcpPubSubSourceNamespaceLister implements the GcpPubSubSourceNamespaceLister -// interface. -type gcpPubSubSourceNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all GcpPubSubSources in the indexer for a given namespace. -func (s gcpPubSubSourceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.GcpPubSubSource, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.GcpPubSubSource)) - }) - return ret, err -} - -// Get retrieves the GcpPubSubSource from the indexer for a given namespace and name. -func (s gcpPubSubSourceNamespaceLister) Get(name string) (*v1alpha1.GcpPubSubSource, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("gcppubsubsource"), name) - } - return obj.(*v1alpha1.GcpPubSubSource), nil -} diff --git a/gcppubsub/pkg/reconciler/doc.go b/gcppubsub/pkg/reconciler/doc.go deleted file mode 100644 index 849e2adc68..0000000000 --- a/gcppubsub/pkg/reconciler/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub implements the GcpPubSubSource controller. -// This is needed to be able to watch channels when delivering to a channel. -// This is needed to be able to watch the sink when delivering messages directly. -package gcppubsub diff --git a/gcppubsub/pkg/reconciler/gcppubsubsource.go b/gcppubsub/pkg/reconciler/gcppubsubsource.go deleted file mode 100644 index c768b09768..0000000000 --- a/gcppubsub/pkg/reconciler/gcppubsubsource.go +++ /dev/null @@ -1,330 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "context" - "fmt" - "log" - "os" - - "cloud.google.com/go/pubsub" - "go.uber.org/zap" - v1 "k8s.io/api/apps/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/sets" - eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" - "knative.dev/pkg/logging" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/manager" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - "knative.dev/eventing-contrib/gcppubsub/pkg/reconciler/resources" - "knative.dev/eventing-contrib/pkg/controller/sdk" - "knative.dev/eventing-contrib/pkg/controller/sinks" - "knative.dev/eventing-contrib/pkg/reconciler/eventtype" -) - -const ( - // controllerAgentName is the string used by this controller to identify - // itself when creating events. - controllerAgentName = "gcp-pubsub-source-controller" - - // raImageEnvVar is the name of the environment variable that contains the receive adapter's - // image. It must be defined. - raImageEnvVar = "GCPPUBSUB_RA_IMAGE" - - finalizerName = controllerAgentName -) - -// Add creates a new GcpPubSubSource Controller and adds it to the Manager with -// default RBAC. The Manager will set fields on the Controller and Start it when -// the Manager is Started. -func Add(mgr manager.Manager, logger *zap.SugaredLogger) error { - raImage, defined := os.LookupEnv(raImageEnvVar) - if !defined { - return fmt.Errorf("required environment variable '%s' not defined", raImageEnvVar) - } - - log.Println("Adding the GCP PubSub Source controller.") - p := &sdk.Provider{ - AgentName: controllerAgentName, - Parent: &v1alpha1.GcpPubSubSource{}, - Owns: []runtime.Object{&v1.Deployment{}, &eventingv1alpha1.EventType{}}, - Reconciler: &reconciler{ - scheme: mgr.GetScheme(), - pubSubClientCreator: gcpPubSubClientCreator, - receiveAdapterImage: raImage, - eventTypeReconciler: eventtype.Reconciler{ - Scheme: mgr.GetScheme(), - }, - }, - } - - return p.Add(mgr, logger) -} - -// gcpPubSubClientCreator creates a real GCP PubSub client. It should always be used, except during -// unit tests. -func gcpPubSubClientCreator(ctx context.Context, googleCloudProject string) (pubSubClient, error) { - // Auth to GCP is handled by having the GOOGLE_APPLICATION_CREDENTIALS environment variable - // pointing at a credential file. - psc, err := pubsub.NewClient(ctx, googleCloudProject) - if err != nil { - return nil, err - } - return &realGcpPubSubClient{ - client: psc, - }, nil -} - -type reconciler struct { - client client.Client - scheme *runtime.Scheme - - pubSubClientCreator pubSubClientCreator - receiveAdapterImage string - eventTypeReconciler eventtype.Reconciler -} - -func (r *reconciler) InjectClient(c client.Client) error { - r.client = c - r.eventTypeReconciler.Client = c - return nil -} - -func (r *reconciler) Reconcile(ctx context.Context, object runtime.Object) error { - logger := logging.FromContext(ctx).Desugar() - - src, ok := object.(*v1alpha1.GcpPubSubSource) - if !ok { - logger.Error("could not find GcpPubSub source", zap.Any("object", object)) - return nil - } - - // This Source attempts to reconcile three things. - // 1. Determine the sink's URI. - // - Nothing to delete. - // 2. Create a receive adapter in the form of a Deployment. - // - Will be garbage collected by K8s when this GcpPubSubSource is deleted. - // 3. Register that receive adapter as a Pull endpoint for the specified GCP PubSub Topic. - // - This needs to deregister during deletion. - // 4. Create the EventTypes that it can emit. - // - Will be garbage collected by K8s when this GcpPubSubSource is deleted. - // Because there is something that must happen during deletion, we add this controller as a - // finalizer to every GcpPubSubSource. - - // See if the source has been deleted. - deletionTimestamp := src.DeletionTimestamp - if deletionTimestamp != nil { - err := r.deleteSubscription(ctx, src) - if err != nil { - logger.Error("Unable to delete the Subscription", zap.Error(err)) - return err - } - r.removeFinalizer(src) - return nil - } - - r.addFinalizer(src) - - src.Status.InitializeConditions() - - sinkURI, err := sinks.GetSinkURI(ctx, r.client, src.Spec.Sink, src.Namespace) - if err != nil { - src.Status.MarkNoSink("NotFound", "") - return err - } - src.Status.MarkSink(sinkURI) - - var transformerURI string - if src.Spec.Transformer != nil { - transformerURI, err = sinks.GetSinkURI(ctx, r.client, src.Spec.Transformer, src.Namespace) - if err != nil { - src.Status.MarkNoTransformer("NotFound", "") - return err - } - src.Status.MarkTransformer(transformerURI) - } - - sub, err := r.createSubscription(ctx, src) - if err != nil { - logger.Error("Unable to create the subscription", zap.Error(err)) - return err - } - src.Status.MarkSubscribed() - - _, err = r.createReceiveAdapter(ctx, src, sub.ID(), sinkURI, transformerURI) - if err != nil { - logger.Error("Unable to create the receive adapter", zap.Error(err)) - return err - } - src.Status.MarkDeployed() - - err = r.reconcileEventTypes(ctx, src) - if err != nil { - logger.Error("Unable to reconcile the event types", zap.Error(err)) - return err - } - src.Status.MarkEventTypes() - - return nil -} - -func (r *reconciler) addFinalizer(s *v1alpha1.GcpPubSubSource) { - finalizers := sets.NewString(s.Finalizers...) - finalizers.Insert(finalizerName) - s.Finalizers = finalizers.List() -} - -func (r *reconciler) removeFinalizer(s *v1alpha1.GcpPubSubSource) { - finalizers := sets.NewString(s.Finalizers...) - finalizers.Delete(finalizerName) - s.Finalizers = finalizers.List() -} - -func (r *reconciler) createReceiveAdapter(ctx context.Context, src *v1alpha1.GcpPubSubSource, subscriptionID, sinkURI, transformerURI string) (*v1.Deployment, error) { - ra, err := r.getReceiveAdapter(ctx, src) - if err != nil && !apierrors.IsNotFound(err) { - logging.FromContext(ctx).Error("Unable to get an existing receive adapter", zap.Error(err)) - return nil, err - } - if ra != nil { - logging.FromContext(ctx).Desugar().Info("Reusing existing receive adapter", zap.Any("receiveAdapter", ra)) - return ra, nil - } - svc := resources.MakeReceiveAdapter(&resources.ReceiveAdapterArgs{ - Image: r.receiveAdapterImage, - Source: src, - Labels: getLabels(src), - SubscriptionID: subscriptionID, - SinkURI: sinkURI, - TransformerURI: transformerURI, - }) - if err := controllerutil.SetControllerReference(src, svc, r.scheme); err != nil { - return nil, err - } - err = r.client.Create(ctx, svc) - logging.FromContext(ctx).Desugar().Info("Receive Adapter created.", zap.Error(err), zap.Any("receiveAdapter", svc)) - return svc, err -} - -func (r *reconciler) getReceiveAdapter(ctx context.Context, src *v1alpha1.GcpPubSubSource) (*v1.Deployment, error) { - dl := &v1.DeploymentList{} - err := r.client.List(ctx, &client.ListOptions{ - Namespace: src.Namespace, - LabelSelector: r.getLabelSelector(src), - // TODO this is only needed by the fake client. Real K8s does not need it. Remove it once - // the fake is fixed. - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1.SchemeGroupVersion.String(), - Kind: "Deployment", - }, - }, - }, - dl) - - if err != nil { - logging.FromContext(ctx).Desugar().Error("Unable to list deployments: %v", zap.Error(err)) - return nil, err - } - for _, dep := range dl.Items { - if metav1.IsControlledBy(&dep, src) { - return &dep, nil - } - } - return nil, apierrors.NewNotFound(schema.GroupResource{}, "") -} - -func (r *reconciler) getLabelSelector(src *v1alpha1.GcpPubSubSource) labels.Selector { - return labels.SelectorFromSet(getLabels(src)) -} - -func getLabels(src *v1alpha1.GcpPubSubSource) map[string]string { - return map[string]string{ - "knative-eventing-source": controllerAgentName, - "knative-eventing-source-name": src.Name, - } -} - -func (r *reconciler) createSubscription(ctx context.Context, src *v1alpha1.GcpPubSubSource) (pubSubSubscription, error) { - psc, err := r.pubSubClientCreator(ctx, src.Spec.GoogleCloudProject) - if err != nil { - return nil, err - } - sub := psc.SubscriptionInProject(generateSubName(src), src.Spec.GoogleCloudProject) - if exists, err := sub.Exists(ctx); err != nil { - return nil, err - } else if exists { - logging.FromContext(ctx).Info("Reusing existing subscription.") - return sub, nil - } - createdSub, err := psc.CreateSubscription(ctx, sub.ID(), pubsub.SubscriptionConfig{ - Topic: psc.Topic(src.Spec.Topic), - }) - if err != nil { - logging.FromContext(ctx).Desugar().Info("Error creating new subscription", zap.Error(err)) - } else { - logging.FromContext(ctx).Desugar().Info("Created new subscription", zap.Any("subscription", createdSub)) - } - return createdSub, err -} - -func (r *reconciler) deleteSubscription(ctx context.Context, src *v1alpha1.GcpPubSubSource) error { - psc, err := r.pubSubClientCreator(ctx, src.Spec.GoogleCloudProject) - if err != nil { - return err - } - sub := psc.SubscriptionInProject(generateSubName(src), src.Spec.GoogleCloudProject) - if exists, err := sub.Exists(ctx); err != nil { - return err - } else if !exists { - return nil - } - return sub.Delete(ctx) -} - -func (r *reconciler) reconcileEventTypes(ctx context.Context, src *v1alpha1.GcpPubSubSource) error { - args := r.newEventTypeReconcilerArgs(src) - return r.eventTypeReconciler.Reconcile(ctx, src, args) -} - -func (r *reconciler) newEventTypeReconcilerArgs(src *v1alpha1.GcpPubSubSource) *eventtype.ReconcilerArgs { - spec := eventingv1alpha1.EventTypeSpec{ - Type: v1alpha1.GcpPubSubSourceEventType, - Source: v1alpha1.GcpPubSubEventSource(src.Spec.GoogleCloudProject, src.Spec.Topic), - Broker: src.Spec.Sink.Name, - } - specs := make([]eventingv1alpha1.EventTypeSpec, 0, 1) - specs = append(specs, spec) - return &eventtype.ReconcilerArgs{ - Specs: specs, - Namespace: src.Namespace, - Labels: getLabels(src), - Kind: src.Spec.Sink.Kind, - } -} - -func generateSubName(src *v1alpha1.GcpPubSubSource) string { - return fmt.Sprintf("knative-eventing-%s-%s-%s", src.Namespace, src.Name, src.UID) -} diff --git a/gcppubsub/pkg/reconciler/gcppubsubsource_test.go b/gcppubsub/pkg/reconciler/gcppubsubsource_test.go deleted file mode 100644 index e8a4e484a0..0000000000 --- a/gcppubsub/pkg/reconciler/gcppubsubsource_test.go +++ /dev/null @@ -1,659 +0,0 @@ -/* -Copyright 2018 The Knative Authors - -Licensed under the Apache License, Veroute.on 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 gcppubsub - -import ( - "context" - "errors" - "fmt" - "testing" - - "cloud.google.com/go/pubsub" - v1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/kubernetes/scheme" - eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1" - eventingsourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1" - duckv1alpha1 "knative.dev/pkg/apis/duck/v1alpha1" - "sigs.k8s.io/controller-runtime/pkg/client" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" - controllertesting "knative.dev/eventing-contrib/pkg/controller/testing" - "knative.dev/eventing-contrib/pkg/reconciler/eventtype" -) - -var ( - // deletionTime is used when objects are marked as deleted. Rfc3339Copy() - // truncates to seconds to match the loss of precision during serialization. - deletionTime = metav1.Now().Rfc3339Copy() - - trueVal = true -) - -const ( - raImage = "test-ra-image" - - pscData = "pubSubClientCreatorData" - - image = "knative.dev/test/image" - sourceName = "test-gcp-pub-sub-source" - sourceUID = "1234-5678-90" - testNS = "testnamespace" - - addressableName = "testsink" - addressableKind = "Sink" - brokerKind = "Broker" - addressableAPIVersion = "duck.knative.dev/v1alpha1" - addressableDNS = "addressable.sink.svc.cluster.local" - addressableURI = "http://addressable.sink.svc.cluster.local" - transformerAddressableName = "testtransformer" -) - -func init() { - // Add types to scheme - v1.AddToScheme(scheme.Scheme) - corev1.AddToScheme(scheme.Scheme) - v1alpha1.SchemeBuilder.AddToScheme(scheme.Scheme) - eventingsourcesv1alpha1.SchemeBuilder.AddToScheme(scheme.Scheme) - duckv1alpha1.AddToScheme(scheme.Scheme) - eventingv1alpha1.AddToScheme(scheme.Scheme) -} - -type pubSubClientCreatorData struct { - clientCreateErr error - subExists bool - subExistsErr error - createSubErr error - deleteSubErr error -} - -func TestReconcile(t *testing.T) { - testCases := []controllertesting.TestCase{ - { - Name: "not a GCP PubSub source", - // This is not a GcpPubSubSource. - Reconciles: getNonGcpPubSubSource(), - InitialState: []runtime.Object{ - getNonGcpPubSubSource(), - }, - }, { - Name: "deleting - cannot create client", - InitialState: []runtime.Object{ - getDeletingSource(), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - clientCreateErr: errors.New("test-induced-error"), - }, - }, - WantErrMsg: "test-induced-error", - }, { - Name: "deleting - error checking subscription exists", - InitialState: []runtime.Object{ - getDeletingSource(), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - subExistsErr: errors.New("test-induced-error"), - }, - }, - WantErrMsg: "test-induced-error", - }, { - Name: "deleting - cannot delete subscription", - InitialState: []runtime.Object{ - getDeletingSource(), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - subExists: true, - deleteSubErr: errors.New("test-induced-error"), - }, - }, - WantErrMsg: "test-induced-error", - }, { - Name: "deleting - remove finalizer", - InitialState: []runtime.Object{ - getDeletingSource(), - }, - WantPresent: []runtime.Object{ - getDeletingSourceWithoutFinalizer(), - }, - }, { - Name: "cannot get sinkURI", - InitialState: []runtime.Object{ - getSource(), - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndNoSink(), - }, - WantErrMsg: "sinks.duck.knative.dev \"testsink\" not found", - }, { - Name: "cannot get transformURI", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndNoTransfomer(), - }, - WantErrMsg: "sinks.duck.knative.dev \"testtransformer\" not found", - }, {}, { - Name: "cannot create client", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - clientCreateErr: errors.New("test-induced-error"), - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformer(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "error checking subscription exists", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - subExistsErr: errors.New("test-induced-error"), - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformer(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "cannot create subscription", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - createSubErr: errors.New("test-induced-error"), - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformer(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "reusing existing subscription - cannot create receive adapter", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - Mocks: controllertesting.Mocks{ - MockCreates: []controllertesting.MockCreate{ - func(_ client.Client, _ context.Context, _ runtime.Object) (controllertesting.MockHandled, error) { - return controllertesting.Handled, errors.New("test-induced-error") - }, - }, - }, - OtherTestData: map[string]interface{}{ - pscData: pubSubClientCreatorData{ - subExists: true, - createSubErr: errors.New("some other error that is not seen, because it is not created"), - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformerAndSubscribed(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "cannot create receive adapter", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - Mocks: controllertesting.Mocks{ - MockCreates: []controllertesting.MockCreate{ - func(_ client.Client, _ context.Context, _ runtime.Object) (controllertesting.MockHandled, error) { - return controllertesting.Handled, errors.New("test-induced-error") - }, - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformerAndSubscribed(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "cannot list deployments", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - Mocks: controllertesting.Mocks{ - MockLists: []controllertesting.MockList{ - func(_ client.Client, _ context.Context, _ *client.ListOptions, _ runtime.Object) (controllertesting.MockHandled, error) { - return controllertesting.Handled, errors.New("test-induced-error") - }, - }, - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformerAndSubscribed(), - }, - WantErrMsg: "test-induced-error", - }, { - Name: "successful create", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - }, - WantPresent: []runtime.Object{ - getReadyAndMarkEventTypeSource(), - }, - }, { - Name: "successful create - reuse existing receive adapter", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - getReceiveAdapter(), - }, - Mocks: controllertesting.Mocks{ - MockCreates: []controllertesting.MockCreate{ - func(_ client.Client, _ context.Context, _ runtime.Object) (controllertesting.MockHandled, error) { - return controllertesting.Handled, errors.New("an error that won't be seen because create is not called") - }, - }, - }, - WantPresent: []runtime.Object{ - getReadyAndMarkEventTypeSource(), - }, - }, { - Name: "successful create event types", - InitialState: []runtime.Object{ - getSourceWithKind(brokerKind), - getAddressableWithNameAndKind(addressableName, brokerKind), - getAddressableWithName(transformerAddressableName), - }, - WantPresent: []runtime.Object{ - getReadyAndMarkEventTypeSourceWithKind(brokerKind), - getEventType(), - }, - }, { - Name: "successful delete event types", - InitialState: []runtime.Object{ - getSource(), - getAddressable(), - getAddressableWithName(transformerAddressableName), - getEventTypeForSource("name-1", getSource()), - }, - WantPresent: []runtime.Object{ - getReadyAndMarkEventTypeSource(), - }, - WantAbsent: []runtime.Object{ - getEventTypeForSource("name-1", getSource()), - }, - }, { - Name: "cannot create event types", - InitialState: []runtime.Object{ - getSourceWithKind(brokerKind), - getAddressableWithNameAndKind(addressableName, brokerKind), - getAddressableWithName(transformerAddressableName), - }, - Mocks: controllertesting.Mocks{ - MockCreates: []controllertesting.MockCreate{ - func(_ client.Client, _ context.Context, obj runtime.Object) (controllertesting.MockHandled, error) { - if _, ok := obj.(*eventingv1alpha1.EventType); ok { - return controllertesting.Handled, errors.New("test-induced-error") - } - return controllertesting.Unhandled, nil - }, - }, - }, - WantAbsent: []runtime.Object{ - getEventType(), - }, - WantPresent: []runtime.Object{ - getSourceWithFinalizerAndSinkAndTransformerAndSubscribedAndDeployedAndKind(brokerKind), - }, - WantErrMsg: "test-induced-error", - }, - } - for _, tc := range testCases { - tc.IgnoreTimes = true - tc.ReconcileKey = fmt.Sprintf("%s/%s", testNS, sourceName) - if tc.Reconciles == nil { - tc.Reconciles = getSource() - } - tc.Scheme = scheme.Scheme - - c := tc.GetClient() - r := &reconciler{ - client: c, - scheme: tc.Scheme, - - pubSubClientCreator: createPubSubClientCreator(tc.OtherTestData[pscData]), - - receiveAdapterImage: raImage, - eventTypeReconciler: eventtype.Reconciler{ - Scheme: tc.Scheme, - }, - } - r.InjectClient(c) - t.Run(tc.Name, tc.Runner(t, r, c)) - } -} - -func getNonGcpPubSubSource() *eventingsourcesv1alpha1.ContainerSource { - obj := &eventingsourcesv1alpha1.ContainerSource{ - TypeMeta: metav1.TypeMeta{ - APIVersion: eventingsourcesv1alpha1.SchemeGroupVersion.String(), - Kind: "ContainerSource", - }, - ObjectMeta: om(testNS, sourceName), - Spec: eventingsourcesv1alpha1.ContainerSourceSpec{ - Template: &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{{ - Image: image, - Args: []string(nil), - }, - }, - }, - }, - Sink: &corev1.ObjectReference{ - Name: addressableName, - Kind: addressableKind, - APIVersion: addressableAPIVersion, - }, - }, - } - // selflink is not filled in when we create the object, so clear it - obj.ObjectMeta.SelfLink = "" - return obj -} - -func getSource() *v1alpha1.GcpPubSubSource { - return getSourceWithKind(addressableKind) -} - -func getSourceWithKind(kind string) *v1alpha1.GcpPubSubSource { - obj := &v1alpha1.GcpPubSubSource{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "GcpPubSubSource", - }, - ObjectMeta: om(testNS, sourceName), - Spec: v1alpha1.GcpPubSubSourceSpec{ - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "cred-secret", - }, - Key: "secret-entry.json", - }, - GoogleCloudProject: "my-gcp-project", - Topic: "laconia", - Sink: &corev1.ObjectReference{ - Name: addressableName, - Kind: kind, - APIVersion: addressableAPIVersion, - }, - Transformer: &corev1.ObjectReference{ - Name: transformerAddressableName, - Kind: addressableKind, - APIVersion: addressableAPIVersion, - }, - }, - } - // selflink is not filled in when we create the object, so clear it - obj.ObjectMeta.SelfLink = "" - return obj -} - -func getEventType() *eventingv1alpha1.EventType { - return getEventTypeForSource("", getSourceWithKind(brokerKind)) -} - -func getEventTypeForSource(name string, src *v1alpha1.GcpPubSubSource) *eventingv1alpha1.EventType { - return &eventingv1alpha1.EventType{ - TypeMeta: metav1.TypeMeta{ - APIVersion: eventingv1alpha1.SchemeGroupVersion.String(), - Kind: "EventType", - }, - ObjectMeta: metav1.ObjectMeta{ - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "GcpPubSubSource", - Name: sourceName, - Controller: &trueVal, - BlockOwnerDeletion: &trueVal, - UID: sourceUID, - }, - }, - Name: name, - GenerateName: fmt.Sprintf("%s-", v1alpha1.GcpPubSubSourceEventType), - Namespace: testNS, - Labels: getLabels(src), - }, - Spec: eventingv1alpha1.EventTypeSpec{ - Type: v1alpha1.GcpPubSubSourceEventType, - Source: v1alpha1.GcpPubSubEventSource("my-gcp-project", "laconia"), - Broker: addressableName, - }, - } -} - -func getDeletingSourceWithoutFinalizer() *v1alpha1.GcpPubSubSource { - src := getSource() - src.DeletionTimestamp = &deletionTime - return src -} - -func getDeletingSource() *v1alpha1.GcpPubSubSource { - src := getDeletingSourceWithoutFinalizer() - src.Finalizers = []string{finalizerName} - return src -} - -func getSourceWithFinalizer() *v1alpha1.GcpPubSubSource { - src := getSource() - src.Finalizers = []string{finalizerName} - src.Status.InitializeConditions() - return src -} - -func getSourceWithFinalizerAndNoSink() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizer() - src.Status.MarkNoSink("NotFound", "") - return src -} - -func getSourceWithFinalizerAndSinkAndNoTransfomer() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizer() - src.Status.MarkSink(addressableURI) - src.Status.MarkNoTransformer("NotFound", "") - return src -} - -func getSourceWithFinalizerAndSink() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizer() - src.Status.MarkSink(addressableURI) - return src -} - -func getSourceWithFinalizerAndSinkAndTransformer() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizerAndSink() - src.Status.MarkTransformer(addressableURI) - return src -} - -func getSourceWithFinalizerAndSinkAndTransformerAndSubscribed() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizerAndSinkAndTransformer() - src.Status.MarkSubscribed() - return src -} - -func getSourceWithFinalizerAndSinkAndTransformerAndSubscribedAndDeployedAndKind(kind string) *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizerAndSinkAndTransformerAndSubscribed() - src.Status.MarkDeployed() - src.Spec.Sink.Kind = kind - return src -} - -func getReadySource() *v1alpha1.GcpPubSubSource { - src := getSourceWithFinalizerAndSinkAndTransformerAndSubscribed() - src.Status.MarkDeployed() - return src -} - -func getReadySourceWithKind(kind string) *v1alpha1.GcpPubSubSource { - src := getReadySource() - src.Spec.Sink.Kind = kind - return src -} - -func getReadyAndMarkEventTypeSource() *v1alpha1.GcpPubSubSource { - src := getReadySource() - src.Status.MarkEventTypes() - return src -} - -func getReadyAndMarkEventTypeSourceWithKind(kind string) *v1alpha1.GcpPubSubSource { - src := getReadySourceWithKind(kind) - src.Status.MarkEventTypes() - return src -} - -func om(namespace, name string) metav1.ObjectMeta { - return metav1.ObjectMeta{ - Namespace: namespace, - Name: name, - SelfLink: fmt.Sprintf("/apis/eventing/sources/v1alpha1/namespaces/%s/object/%s", namespace, name), - UID: sourceUID, - } -} - -func createPubSubClientCreator(value interface{}) pubSubClientCreator { - var data pubSubClientCreatorData - var ok bool - if data, ok = value.(pubSubClientCreatorData); !ok { - data = pubSubClientCreatorData{} - } - if data.clientCreateErr != nil { - return func(_ context.Context, _ string) (pubSubClient, error) { - return nil, data.clientCreateErr - } - } - return func(_ context.Context, _ string) (pubSubClient, error) { - return &fakePubSubClient{ - data: data, - }, nil - } -} - -func getAddressable() *unstructured.Unstructured { - return getAddressableWithNameAndKind(addressableName, addressableKind) -} - -func getAddressableWithName(name string) *unstructured.Unstructured { - return getAddressableWithNameAndKind(name, addressableKind) -} - -func getAddressableWithNameAndKind(name, kind string) *unstructured.Unstructured { - return &unstructured.Unstructured{ - Object: map[string]interface{}{ - "apiVersion": addressableAPIVersion, - "kind": kind, - "metadata": map[string]interface{}{ - "namespace": testNS, - "name": name, - }, - "status": map[string]interface{}{ - "address": map[string]interface{}{ - "hostname": addressableDNS, - }, - }, - }, - } -} - -func getReceiveAdapter() *v1.Deployment { - return &v1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - OwnerReferences: []metav1.OwnerReference{ - { - Controller: &trueVal, - UID: sourceUID, - }, - }, - Labels: getLabels(getSource()), - Namespace: testNS, - }, - TypeMeta: metav1.TypeMeta{ - APIVersion: v1.SchemeGroupVersion.String(), - Kind: "Deployment", - }, - } -} - -type fakePubSubClient struct { - data pubSubClientCreatorData -} - -func (c *fakePubSubClient) SubscriptionInProject(id, projectId string) pubSubSubscription { - return &fakePubSubSubscription{ - data: c.data, - } -} - -func (c *fakePubSubClient) CreateSubscription(ctx context.Context, id string, cfg pubsub.SubscriptionConfig) (pubSubSubscription, error) { - if c.data.createSubErr != nil { - return nil, c.data.createSubErr - } - return &fakePubSubSubscription{ - data: c.data, - }, nil -} - -func (c *fakePubSubClient) Topic(name string) *pubsub.Topic { - return &pubsub.Topic{} -} - -type fakePubSubSubscription struct { - data pubSubClientCreatorData -} - -func (s *fakePubSubSubscription) Exists(ctx context.Context) (bool, error) { - return s.data.subExists, s.data.subExistsErr -} - -func (s *fakePubSubSubscription) ID() string { - return "fake-pub-sub-id" -} - -func (s *fakePubSubSubscription) Delete(ctx context.Context) error { - return s.data.deleteSubErr -} diff --git a/gcppubsub/pkg/reconciler/pubsub_wrapper.go b/gcppubsub/pkg/reconciler/pubsub_wrapper.go deleted file mode 100644 index cfa39afedc..0000000000 --- a/gcppubsub/pkg/reconciler/pubsub_wrapper.go +++ /dev/null @@ -1,80 +0,0 @@ -/* -Copyright 2018 The Knative 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 gcppubsub - -import ( - "context" - "fmt" - - "cloud.google.com/go/pubsub" -) - -// This file exists so that we can unit test failures with the PubSub client. - -// pubSubClientCreator creates a pubSubClient. -type pubSubClientCreator func(ctx context.Context, googleCloudProject string) (pubSubClient, error) - -// pubSubClient is the set of methods we use on pubsub.Client. -type pubSubClient interface { - SubscriptionInProject(id, projectId string) pubSubSubscription - CreateSubscription(ctx context.Context, id string, cfg pubsub.SubscriptionConfig) (pubSubSubscription, error) - Topic(name string) *pubsub.Topic -} - -// realGcpPubSubClient is the client that will be used everywhere except unit tests. Verify that it -// satisfies the interface. -var _ pubSubClient = &realGcpPubSubClient{} - -// realGcpPubSubClient wraps a real GCP PubSub client, so that it matches the pubSubClient -// interface. It is needed because the real SubscriptionInProject returns a struct and does not -// implicitly match gcpPubSubClient, which returns an interface. -type realGcpPubSubClient struct { - client *pubsub.Client -} - -func (c *realGcpPubSubClient) SubscriptionInProject(id, projectId string) pubSubSubscription { - if c.client != nil { - return c.client.SubscriptionInProject(id, projectId) - } - return nil -} - -func (c *realGcpPubSubClient) CreateSubscription(ctx context.Context, id string, cfg pubsub.SubscriptionConfig) (pubSubSubscription, error) { - if c.client != nil { - return c.client.CreateSubscription(ctx, id, cfg) - } - return nil, fmt.Errorf("pubsub client is nil") -} - -func (c *realGcpPubSubClient) Topic(id string) *pubsub.Topic { - if c.client != nil { - return c.client.Topic(id) - } - return nil -} - -// pubSubSubscription is the set of methods we use on pubsub.Subscription. It exists to make -// pubSubClient unit testable. -type pubSubSubscription interface { - Exists(ctx context.Context) (bool, error) - ID() string - Delete(ctx context.Context) error -} - -// pubsub.Subscription is the real pubSubSubscription that is used everywhere except unit tests. -// Verify that it satisfies the interface. -var _ pubSubSubscription = &pubsub.Subscription{} diff --git a/gcppubsub/pkg/reconciler/pubsub_wrapper_test.go b/gcppubsub/pkg/reconciler/pubsub_wrapper_test.go deleted file mode 100644 index 585a66ada2..0000000000 --- a/gcppubsub/pkg/reconciler/pubsub_wrapper_test.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2019 The Knative Authors - -Licensed under the Apache License, Veroute.on 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 gcppubsub - -import ( - "context" - "testing" - - "cloud.google.com/go/pubsub" -) - -func TestPubSubWrapperFluff(t *testing.T) { - c := &realGcpPubSubClient{} - - c.SubscriptionInProject("foo", "bar") - - c.Topic("foo") - - c.CreateSubscription(context.TODO(), "foo", pubsub.SubscriptionConfig{}) -} diff --git a/gcppubsub/pkg/reconciler/resources/receive_adapter.go b/gcppubsub/pkg/reconciler/resources/receive_adapter.go deleted file mode 100644 index e333ab163a..0000000000 --- a/gcppubsub/pkg/reconciler/resources/receive_adapter.go +++ /dev/null @@ -1,122 +0,0 @@ -/* -Copyright 2018 The Knative 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 resources - -import ( - "fmt" - - v1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -// ReceiveAdapterArgs are the arguments needed to create a GCP PubSub Source Receive Adapter. Every -// field is required. -type ReceiveAdapterArgs struct { - Image string - Source *v1alpha1.GcpPubSubSource - Labels map[string]string - SubscriptionID string - SinkURI string - TransformerURI string -} - -const ( - credsVolume = "google-cloud-key" - credsMountPath = "/var/secrets/google" -) - -// MakeReceiveAdapter generates (but does not insert into K8s) the Receive Adapter Deployment for -// GCP PubSub Sources. -func MakeReceiveAdapter(args *ReceiveAdapterArgs) *v1.Deployment { - credsFile := fmt.Sprintf("%s/%s", credsMountPath, args.Source.Spec.GcpCredsSecret.Key) - replicas := int32(1) - return &v1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: args.Source.Namespace, - GenerateName: fmt.Sprintf("gcppubsub-%s-", args.Source.Name), - Labels: args.Labels, - }, - Spec: v1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: args.Labels, - }, - Replicas: &replicas, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - "sidecar.istio.io/inject": "true", - }, - Labels: args.Labels, - }, - Spec: corev1.PodSpec{ - ServiceAccountName: args.Source.Spec.ServiceAccountName, - Containers: []corev1.Container{ - { - Name: "receive-adapter", - Image: args.Image, - Env: []corev1.EnvVar{ - { - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: credsFile, - }, - { - Name: "GCPPUBSUB_PROJECT", - Value: args.Source.Spec.GoogleCloudProject, - }, - { - Name: "GCPPUBSUB_TOPIC", - Value: args.Source.Spec.Topic, - }, - { - Name: "GCPPUBSUB_SUBSCRIPTION_ID", - Value: args.SubscriptionID, - }, - { - Name: "SINK_URI", - Value: args.SinkURI, - }, - { - Name: "TRANSFORMER_URI", - Value: args.TransformerURI, - }, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: credsVolume, - MountPath: credsMountPath, - }, - }, - }, - }, - Volumes: []corev1.Volume{ - { - Name: credsVolume, - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: args.Source.Spec.GcpCredsSecret.Name, - }, - }, - }, - }, - }, - }, - }, - } -} diff --git a/gcppubsub/pkg/reconciler/resources/receive_adapter_test.go b/gcppubsub/pkg/reconciler/resources/receive_adapter_test.go deleted file mode 100644 index 539eb82d24..0000000000 --- a/gcppubsub/pkg/reconciler/resources/receive_adapter_test.go +++ /dev/null @@ -1,147 +0,0 @@ -/* -Copyright 2018 The Knative 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 resources - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - v1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "knative.dev/eventing-contrib/gcppubsub/pkg/apis/sources/v1alpha1" -) - -func TestMakeReceiveAdapter(t *testing.T) { - src := &v1alpha1.GcpPubSubSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "source-name", - Namespace: "source-namespace", - }, - Spec: v1alpha1.GcpPubSubSourceSpec{ - ServiceAccountName: "source-svc-acct", - GoogleCloudProject: "gcp-name", - Topic: "topic", - GcpCredsSecret: corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "gcp-secret-name", - }, - Key: "gcp-secret-key", - }, - }, - } - - got := MakeReceiveAdapter(&ReceiveAdapterArgs{ - Image: "test-image", - Source: src, - Labels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", - }, - SubscriptionID: "sub-id", - SinkURI: "sink-uri", - TransformerURI: "transformer-uri", - }) - - one := int32(1) - want := &v1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: "source-namespace", - GenerateName: "gcppubsub-source-name-", - Labels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", - }, - }, - Spec: v1.DeploymentSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", - }, - }, - Replicas: &one, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - "sidecar.istio.io/inject": "true", - }, - Labels: map[string]string{ - "test-key1": "test-value1", - "test-key2": "test-value2", - }, - }, - Spec: corev1.PodSpec{ - ServiceAccountName: "source-svc-acct", - Containers: []corev1.Container{ - { - Name: "receive-adapter", - Image: "test-image", - Env: []corev1.EnvVar{ - { - Name: "GOOGLE_APPLICATION_CREDENTIALS", - Value: "/var/secrets/google/gcp-secret-key", - }, - { - Name: "GCPPUBSUB_PROJECT", - Value: "gcp-name", - }, - { - Name: "GCPPUBSUB_TOPIC", - Value: "topic", - }, - { - Name: "GCPPUBSUB_SUBSCRIPTION_ID", - Value: "sub-id", - }, - { - Name: "SINK_URI", - Value: "sink-uri", - }, - { - Name: "TRANSFORMER_URI", - Value: "transformer-uri", - }, - }, - VolumeMounts: []corev1.VolumeMount{ - { - Name: credsVolume, - MountPath: credsMountPath, - }, - }, - }, - }, - Volumes: []corev1.Volume{ - { - Name: credsVolume, - VolumeSource: corev1.VolumeSource{ - Secret: &corev1.SecretVolumeSource{ - SecretName: "gcp-secret-name", - }, - }, - }, - }, - }, - }, - }, - } - - if diff := cmp.Diff(want, got); diff != "" { - t.Errorf("unexpected deploy (-want, +got) = %v", diff) - } -} diff --git a/gcppubsub/samples/README.md b/gcppubsub/samples/README.md deleted file mode 100644 index eb9ec19b22..0000000000 --- a/gcppubsub/samples/README.md +++ /dev/null @@ -1,164 +0,0 @@ -# GCP Cloud Pub/Sub - Source - -[See the Knative documentation for a full example of this source.](https://github.com/knative/docs/tree/master/docs/eventing/samples/gcp-pubsub-source) - -This sample shows how to configure the GCP PubSub event source. This event -source is most useful as a bridge from other GCP services, such as -[Cloud Storage](https://cloud.google.com/storage/docs/pubsub-notifications), -[IoT Core](https://cloud.google.com/iot/docs/how-tos/devices) and -[Cloud Scheduler](https://cloud.google.com/scheduler/docs/creating#). - -## Deployment Steps - -These steps assume that you have checked out the repo and have a shell in this -`samples` directory. - -### Prerequisites - -1. Create a - [Google Cloud Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects). -1. Enable the 'Cloud Pub/Sub API' on that project. - - ```shell - gcloud services enable pubsub.googleapis.com - ``` - -1. Install the [GCP PubSub Source from this directory](../config/) from source: - - ```shell - ko apply --filename https://github.com/knative/eventing-contrib/tree/master/gcppubsub/config/ - ``` - - Or install a release version (TODO: link to released component). - -1. Create a GCP - [Service Account](https://console.cloud.google.com/iam-admin/serviceaccounts/project). - It is simplest to create a single account for both registering subscriptions - and reading messages, but it is possible to separate the accounts for the - controller (which creates PubSub subscriptions) and the receive adapter - (which reads the messages from the subscription). This is left as an exercise - for the reader. - - 1. Create a new service account named `knative-source` with the following - command: - - ```shell - gcloud iam service-accounts create knative-source - ``` - - 1. Give that Service Account the 'Pub/Sub Editor' role on your GCP project: - - ```shell - gcloud projects add-iam-policy-binding $PROJECT_ID \ - --member=serviceAccount:knative-source@$PROJECT_ID.iam.gserviceaccount.com \ - --role roles/pubsub.editor - ``` - - 1. Download a new JSON private key for that Service Account. **Be sure not to - check this key into source control!** - - ```shell - gcloud iam service-accounts keys create knative-source.json \ - --iam-account=knative-source@$PROJECT_ID.iam.gserviceaccount.com - ``` - - 1. Create two secrets on the kubernetes cluster with the downloaded key: - - ```shell - # Note that the first secret may already have been created when installing - # Knative Eventing. The following command will overwrite it. If you don't - # want to overwrite it, then skip this command. - kubectl -n knative-sources create secret generic gcppubsub-source-key --from-file=key.json=knative-source.json --dry-run -o yaml | kubectl apply --filename - - - # The second secret should not already exist, so just try to create it. - kubectl -n default create secret generic google-cloud-key --from-file=key.json=knative-source.json - ``` - - `gcppubsub-source-key` and `key.json` are pre-configured values in the - `gcppubsub-controller` StatefulSet which manages your Eventing sources. - - `google-cloud-key` and `key.json` are pre-configured values in - [`gcp-pubsub-source.yaml`](gcp-pubsub-source.yaml). If you choose to - create a second account, this account only needs - `roles/pubsub.Subscriber`. - -### Deployment - -1. Decide on a topic name, and export variables for your GCP project ID and - topic name in your shell: - - ```shell - export PROJECT_ID=$(gcloud config get-value project) - export TOPIC_NAME=laconia - ``` - -1. Create a GCP PubSub Topic. Set `$TOPIC_NAME` to the name of the topic you - want to receive on. This will be used in subsequent steps as well. - - ```shell - gcloud pubsub topics create $TOPIC_NAME - ``` - -1. Replace the place holders in `gcp-pubsub-source.yaml`. - - - `MY_GCP_PROJECT` should be replaced with your - [Google Cloud Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects)'s - ID. - - - `TOPIC_NAME` should be replaced with your GCP PubSub Topic's name. It - should be the unique portion within the project. E.g. `laconia`, not - `projects/my-gcp-project/topics/laconia`. - - - `event-display` should be replaced with the name of the `Addressable` you - want messages sent to. If you deployed the event display Service as the - destination for messages, you can leave this as `event-display`. - - - `gcpCredsSecret` should be replaced if you are using a non-default secret - or key name for the receive adapter's credentials. - - You can do this with `sed`: - - ```shell - sed -e "s/MY_GCP_PROJECT/$PROJECT_ID/g" -e "s/TOPIC_NAME/$TOPIC_NAME/g" gcp-pubsub-source.yaml | kubectl apply -f - - ``` - -### Subscriber - -In order to check the `GcpPubSubSource` is fully working, we will create a -simple Knative Service that displays incoming events to its log, and direct the -PubSub source to send messages directly (i.e. without buffering or fanout within -the cluster). - -Deploy `event-display.yaml`, building it from source: - -```shell -ko apply -f event-display.yaml -``` - -### Publish - -Publish messages to your GCP PubSub Topic. - -```shell -gcloud pubsub topics publish $TOPIC_NAME --message="Hello World!" -``` - -### Verify - -We will verify that the published message was sent into the Knative eventing -system by looking at what is downstream of the `GcpPubSubSource`. If you -deployed the [Subscriber](#subscriber), then continue using this section. If -not, then you will need to look downstream yourself. - -1. Use [`kail`](https://github.com/boz/kail) to tail the logs of the subscriber. - - ```shell - kail -d event-display --since=10m - ``` - -You should see log lines similar to: - -``` -{"ID":"284375451531353","Data":"SGVsbG8gV29ybGQh","Attributes":null,"PublishTime":"2018-10-31T00:00:00.00Z"} - -``` diff --git a/gcppubsub/samples/event-display.yaml b/gcppubsub/samples/event-display.yaml deleted file mode 100644 index 78a879f6f9..0000000000 --- a/gcppubsub/samples/event-display.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2019 The Knative 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. - -# This is a very simple Knative Service that writes the incoming CloudEvent to its log. -apiVersion: apps/v1 -kind: Deployment -metadata: - name: event-display -spec: - selector: - matchLabels: - app: event-display - template: - metadata: - labels: - app: event-display - spec: - containers: - - name: user-container - image: knative.dev/eventing-contrib/cmd/event_display - ports: - - containerPort: 8080 ---- -apiVersion: v1 -kind: Service -metadata: - name: event-display -spec: - selector: - app: event-display - ports: - - protocol: TCP - port: 80 - targetPort: 8080 diff --git a/gcppubsub/samples/gcp-pubsub-source.yaml b/gcppubsub/samples/gcp-pubsub-source.yaml deleted file mode 100644 index 754fd7128b..0000000000 --- a/gcppubsub/samples/gcp-pubsub-source.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2019 The Knative 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. - -# Replace the following before applying this file: -# TOPIC_NAME: Replace with the GCP PubSub Topic name. -# MY_GCP_PROJECT: Replace with the GCP Project's ID. - -apiVersion: sources.eventing.knative.dev/v1alpha1 -kind: GcpPubSubSource -metadata: - name: TOPIC_NAME-source -spec: - gcpCredsSecret: - name: google-cloud-key - key: key.json - googleCloudProject: MY_GCP_PROJECT - topic: TOPIC_NAME - sink: - apiVersion: v1 - kind: Service - name: event-display diff --git a/hack/release.sh b/hack/release.sh index bf400a77d6..c3ab988af9 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -23,7 +23,6 @@ source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/release.sh declare -A COMPONENTS COMPONENTS=( ["github.yaml"]="github/config" - ["gcppubsub.yaml"]="gcppubsub/config" ["event-display.yaml"]="config/tools/event-display" ["camel.yaml"]="camel/source/config" ["kafka-importer.yaml"]="kafka/source/config" diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 423ecf9d0a..d79e22b191 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,9 +23,9 @@ source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/library.sh CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../../k8s.io/code-generator)} # Generate based on annotations -go generate ./pkg/... ./cmd/... ./github/pkg/... ./gcppubsub/pkg/... ./camel/source/pkg/... ./kafka/source/pkg/... ./kafka/channel/pkg/... ./awssqs/pkg/... +go generate ./pkg/... ./cmd/... ./github/pkg/... ./camel/source/pkg/... ./kafka/source/pkg/... ./kafka/channel/pkg/... ./awssqs/pkg/... -API_DIRS=(github/pkg gcppubsub/pkg camel/source/pkg kafka/source/pkg awssqs/pkg) +API_DIRS=(github/pkg camel/source/pkg kafka/source/pkg awssqs/pkg) for DIR in "${API_DIRS[@]}"; do # generate the code with: diff --git a/hack/update-deps.sh b/hack/update-deps.sh index f602b09617..8e62b77f07 100755 --- a/hack/update-deps.sh +++ b/hack/update-deps.sh @@ -30,4 +30,4 @@ rm -rf $(find vendor/ -name 'BUILD') rm -rf $(find vendor/ -name 'BUILD.bazel') rm -fr vendor/knative.dev/test-infra/devstats -update_licenses third_party/VENDOR-LICENSE "./cmd/*" "./github/cmd/*" "./gcppubsub/cmd/*" "./camel/source/cmd/*" "./kafka/source/cmd/*" "./kafka/channel/cmd/*" "./awssqs/cmd/*" +update_licenses third_party/VENDOR-LICENSE "./cmd/*" "./github/cmd/*" "./camel/source/cmd/*" "./kafka/source/cmd/*" "./kafka/channel/cmd/*" "./awssqs/cmd/*" diff --git a/vendor/cloud.google.com/go/pubsub/apiv1/doc.go b/vendor/cloud.google.com/go/pubsub/apiv1/doc.go deleted file mode 100644 index ccdce27d66..0000000000 --- a/vendor/cloud.google.com/go/pubsub/apiv1/doc.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2018 Google LLC -// -// 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 -// -// https://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. - -// AUTO-GENERATED CODE. DO NOT EDIT. - -// Package pubsub is an auto-generated package for the -// Google Cloud Pub/Sub API. -// -// NOTE: This package is in alpha. It is not stable, and is likely to change. -// -// Provides reliable, many-to-many, asynchronous messaging between -// applications. -// -// Use the client at cloud.google.com/go/pubsub in preference to this. -package pubsub // import "cloud.google.com/go/pubsub/apiv1" - -import ( - "golang.org/x/net/context" - "google.golang.org/grpc/metadata" -) - -func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { - out, _ := metadata.FromOutgoingContext(ctx) - out = out.Copy() - for _, md := range mds { - for k, v := range md { - out[k] = append(out[k], v...) - } - } - return metadata.NewOutgoingContext(ctx, out) -} - -// DefaultAuthScopes reports the default set of authentication scopes to use with this package. -func DefaultAuthScopes() []string { - return []string{ - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/pubsub", - } -} diff --git a/vendor/cloud.google.com/go/pubsub/apiv1/path_funcs.go b/vendor/cloud.google.com/go/pubsub/apiv1/path_funcs.go deleted file mode 100644 index b9ab4848db..0000000000 --- a/vendor/cloud.google.com/go/pubsub/apiv1/path_funcs.go +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2018 Google LLC -// -// 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 -// -// https://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 pubsub - -// PublisherProjectPath returns the path for the project resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s", project) -// instead. -func PublisherProjectPath(project string) string { - return "" + - "projects/" + - project + - "" -} - -// PublisherTopicPath returns the path for the topic resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s/topics/%s", project, topic) -// instead. -func PublisherTopicPath(project, topic string) string { - return "" + - "projects/" + - project + - "/topics/" + - topic + - "" -} - -// SubscriberProjectPath returns the path for the project resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s", project) -// instead. -func SubscriberProjectPath(project string) string { - return "" + - "projects/" + - project + - "" -} - -// SubscriberSnapshotPath returns the path for the snapshot resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s/snapshots/%s", project, snapshot) -// instead. -func SubscriberSnapshotPath(project, snapshot string) string { - return "" + - "projects/" + - project + - "/snapshots/" + - snapshot + - "" -} - -// SubscriberSubscriptionPath returns the path for the subscription resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s/subscriptions/%s", project, subscription) -// instead. -func SubscriberSubscriptionPath(project, subscription string) string { - return "" + - "projects/" + - project + - "/subscriptions/" + - subscription + - "" -} - -// SubscriberTopicPath returns the path for the topic resource. -// -// Deprecated: Use -// fmt.Sprintf("projects/%s/topics/%s", project, topic) -// instead. -func SubscriberTopicPath(project, topic string) string { - return "" + - "projects/" + - project + - "/topics/" + - topic + - "" -} diff --git a/vendor/cloud.google.com/go/pubsub/apiv1/publisher_client.go b/vendor/cloud.google.com/go/pubsub/apiv1/publisher_client.go deleted file mode 100644 index 6e9b1faee1..0000000000 --- a/vendor/cloud.google.com/go/pubsub/apiv1/publisher_client.go +++ /dev/null @@ -1,398 +0,0 @@ -// Copyright 2018 Google LLC -// -// 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 -// -// https://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. - -// AUTO-GENERATED CODE. DO NOT EDIT. - -package pubsub - -import ( - "math" - "time" - - "cloud.google.com/go/iam" - "cloud.google.com/go/internal/version" - gax "github.com/googleapis/gax-go" - "golang.org/x/net/context" - "google.golang.org/api/iterator" - "google.golang.org/api/option" - "google.golang.org/api/transport" - pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" -) - -// PublisherCallOptions contains the retry settings for each method of PublisherClient. -type PublisherCallOptions struct { - CreateTopic []gax.CallOption - UpdateTopic []gax.CallOption - Publish []gax.CallOption - GetTopic []gax.CallOption - ListTopics []gax.CallOption - ListTopicSubscriptions []gax.CallOption - DeleteTopic []gax.CallOption -} - -func defaultPublisherClientOptions() []option.ClientOption { - return []option.ClientOption{ - option.WithEndpoint("pubsub.googleapis.com:443"), - option.WithScopes(DefaultAuthScopes()...), - } -} - -func defaultPublisherCallOptions() *PublisherCallOptions { - retry := map[[2]string][]gax.CallOption{ - {"default", "idempotent"}: { - gax.WithRetry(func() gax.Retryer { - return gax.OnCodes([]codes.Code{ - codes.DeadlineExceeded, - codes.Unavailable, - }, gax.Backoff{ - Initial: 100 * time.Millisecond, - Max: 60000 * time.Millisecond, - Multiplier: 1.3, - }) - }), - }, - {"messaging", "one_plus_delivery"}: { - gax.WithRetry(func() gax.Retryer { - return gax.OnCodes([]codes.Code{ - codes.Aborted, - codes.Canceled, - codes.DeadlineExceeded, - codes.Internal, - codes.ResourceExhausted, - codes.Unavailable, - codes.Unknown, - }, gax.Backoff{ - Initial: 100 * time.Millisecond, - Max: 60000 * time.Millisecond, - Multiplier: 1.3, - }) - }), - }, - } - return &PublisherCallOptions{ - CreateTopic: retry[[2]string{"default", "idempotent"}], - UpdateTopic: retry[[2]string{"default", "idempotent"}], - Publish: retry[[2]string{"messaging", "one_plus_delivery"}], - GetTopic: retry[[2]string{"default", "idempotent"}], - ListTopics: retry[[2]string{"default", "idempotent"}], - ListTopicSubscriptions: retry[[2]string{"default", "idempotent"}], - DeleteTopic: retry[[2]string{"default", "idempotent"}], - } -} - -// PublisherClient is a client for interacting with Google Cloud Pub/Sub API. -type PublisherClient struct { - // The connection to the service. - conn *grpc.ClientConn - - // The gRPC API client. - publisherClient pubsubpb.PublisherClient - - // The call options for this service. - CallOptions *PublisherCallOptions - - // The x-goog-* metadata to be sent with each request. - xGoogMetadata metadata.MD -} - -// NewPublisherClient creates a new publisher client. -// -// The service that an application uses to manipulate topics, and to send -// messages to a topic. -func NewPublisherClient(ctx context.Context, opts ...option.ClientOption) (*PublisherClient, error) { - conn, err := transport.DialGRPC(ctx, append(defaultPublisherClientOptions(), opts...)...) - if err != nil { - return nil, err - } - c := &PublisherClient{ - conn: conn, - CallOptions: defaultPublisherCallOptions(), - - publisherClient: pubsubpb.NewPublisherClient(conn), - } - c.SetGoogleClientInfo() - return c, nil -} - -// Connection returns the client's connection to the API service. -func (c *PublisherClient) Connection() *grpc.ClientConn { - return c.conn -} - -// Close closes the connection to the API service. The user should invoke this when -// the client is no longer required. -func (c *PublisherClient) Close() error { - return c.conn.Close() -} - -// SetGoogleClientInfo sets the name and version of the application in -// the `x-goog-api-client` header passed on each request. Intended for -// use by Google-written clients. -func (c *PublisherClient) SetGoogleClientInfo(keyval ...string) { - kv := append([]string{"gl-go", version.Go()}, keyval...) - kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version) - c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) -} - -func (c *PublisherClient) SubscriptionIAM(subscription *pubsubpb.Subscription) *iam.Handle { - return iam.InternalNewHandle(c.Connection(), subscription.Name) -} - -func (c *PublisherClient) TopicIAM(topic *pubsubpb.Topic) *iam.Handle { - return iam.InternalNewHandle(c.Connection(), topic.Name) -} - -// CreateTopic creates the given topic with the given name. -func (c *PublisherClient) CreateTopic(ctx context.Context, req *pubsubpb.Topic, opts ...gax.CallOption) (*pubsubpb.Topic, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.CreateTopic[0:len(c.CallOptions.CreateTopic):len(c.CallOptions.CreateTopic)], opts...) - var resp *pubsubpb.Topic - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.CreateTopic(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// UpdateTopic updates an existing topic. Note that certain properties of a topic are not -// modifiable. Options settings follow the style guide: -// NOTE: The style guide requires body: "topic" instead of body: "*". -// Keeping the latter for internal consistency in V1, however it should be -// corrected in V2. See -// https://cloud.google.com/apis/design/standard_methods#update for details. -func (c *PublisherClient) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.UpdateTopic[0:len(c.CallOptions.UpdateTopic):len(c.CallOptions.UpdateTopic)], opts...) - var resp *pubsubpb.Topic - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.UpdateTopic(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// Publish adds one or more messages to the topic. Returns NOT_FOUND if the topic -// does not exist. The message payload must not be empty; it must contain -// either a non-empty data field, or at least one attribute. -func (c *PublisherClient) Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.Publish[0:len(c.CallOptions.Publish):len(c.CallOptions.Publish)], opts...) - var resp *pubsubpb.PublishResponse - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.Publish(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// GetTopic gets the configuration of a topic. -func (c *PublisherClient) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.GetTopic[0:len(c.CallOptions.GetTopic):len(c.CallOptions.GetTopic)], opts...) - var resp *pubsubpb.Topic - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.GetTopic(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// ListTopics lists matching topics. -func (c *PublisherClient) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest, opts ...gax.CallOption) *TopicIterator { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ListTopics[0:len(c.CallOptions.ListTopics):len(c.CallOptions.ListTopics)], opts...) - it := &TopicIterator{} - it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Topic, string, error) { - var resp *pubsubpb.ListTopicsResponse - req.PageToken = pageToken - if pageSize > math.MaxInt32 { - req.PageSize = math.MaxInt32 - } else { - req.PageSize = int32(pageSize) - } - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.ListTopics(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, "", err - } - return resp.Topics, resp.NextPageToken, nil - } - fetch := func(pageSize int, pageToken string) (string, error) { - items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) - if err != nil { - return "", err - } - it.items = append(it.items, items...) - return nextPageToken, nil - } - it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) - return it -} - -// ListTopicSubscriptions lists the name of the subscriptions for this topic. -func (c *PublisherClient) ListTopicSubscriptions(ctx context.Context, req *pubsubpb.ListTopicSubscriptionsRequest, opts ...gax.CallOption) *StringIterator { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ListTopicSubscriptions[0:len(c.CallOptions.ListTopicSubscriptions):len(c.CallOptions.ListTopicSubscriptions)], opts...) - it := &StringIterator{} - it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) { - var resp *pubsubpb.ListTopicSubscriptionsResponse - req.PageToken = pageToken - if pageSize > math.MaxInt32 { - req.PageSize = math.MaxInt32 - } else { - req.PageSize = int32(pageSize) - } - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.publisherClient.ListTopicSubscriptions(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, "", err - } - return resp.Subscriptions, resp.NextPageToken, nil - } - fetch := func(pageSize int, pageToken string) (string, error) { - items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) - if err != nil { - return "", err - } - it.items = append(it.items, items...) - return nextPageToken, nil - } - it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) - return it -} - -// DeleteTopic deletes the topic with the given name. Returns NOT_FOUND if the topic -// does not exist. After a topic is deleted, a new topic may be created with -// the same name; this is an entirely new topic with none of the old -// configuration or subscriptions. Existing subscriptions to this topic are -// not deleted, but their topic field is set to _deleted-topic_. -func (c *PublisherClient) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.DeleteTopic[0:len(c.CallOptions.DeleteTopic):len(c.CallOptions.DeleteTopic)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.publisherClient.DeleteTopic(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// StringIterator manages a stream of string. -type StringIterator struct { - items []string - pageInfo *iterator.PageInfo - nextFunc func() error - - // InternalFetch is for use by the Google Cloud Libraries only. - // It is not part of the stable interface of this package. - // - // InternalFetch returns results from a single call to the underlying RPC. - // The number of results is no greater than pageSize. - // If there are no more results, nextPageToken is empty and err is nil. - InternalFetch func(pageSize int, pageToken string) (results []string, nextPageToken string, err error) -} - -// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. -func (it *StringIterator) PageInfo() *iterator.PageInfo { - return it.pageInfo -} - -// Next returns the next result. Its second return value is iterator.Done if there are no more -// results. Once Next returns Done, all subsequent calls will return Done. -func (it *StringIterator) Next() (string, error) { - var item string - if err := it.nextFunc(); err != nil { - return item, err - } - item = it.items[0] - it.items = it.items[1:] - return item, nil -} - -func (it *StringIterator) bufLen() int { - return len(it.items) -} - -func (it *StringIterator) takeBuf() interface{} { - b := it.items - it.items = nil - return b -} - -// TopicIterator manages a stream of *pubsubpb.Topic. -type TopicIterator struct { - items []*pubsubpb.Topic - pageInfo *iterator.PageInfo - nextFunc func() error - - // InternalFetch is for use by the Google Cloud Libraries only. - // It is not part of the stable interface of this package. - // - // InternalFetch returns results from a single call to the underlying RPC. - // The number of results is no greater than pageSize. - // If there are no more results, nextPageToken is empty and err is nil. - InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Topic, nextPageToken string, err error) -} - -// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. -func (it *TopicIterator) PageInfo() *iterator.PageInfo { - return it.pageInfo -} - -// Next returns the next result. Its second return value is iterator.Done if there are no more -// results. Once Next returns Done, all subsequent calls will return Done. -func (it *TopicIterator) Next() (*pubsubpb.Topic, error) { - var item *pubsubpb.Topic - if err := it.nextFunc(); err != nil { - return item, err - } - item = it.items[0] - it.items = it.items[1:] - return item, nil -} - -func (it *TopicIterator) bufLen() int { - return len(it.items) -} - -func (it *TopicIterator) takeBuf() interface{} { - b := it.items - it.items = nil - return b -} diff --git a/vendor/cloud.google.com/go/pubsub/apiv1/subscriber_client.go b/vendor/cloud.google.com/go/pubsub/apiv1/subscriber_client.go deleted file mode 100644 index a2266a3a4d..0000000000 --- a/vendor/cloud.google.com/go/pubsub/apiv1/subscriber_client.go +++ /dev/null @@ -1,593 +0,0 @@ -// Copyright 2018 Google LLC -// -// 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 -// -// https://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. - -// AUTO-GENERATED CODE. DO NOT EDIT. - -package pubsub - -import ( - "math" - "time" - - "cloud.google.com/go/iam" - "cloud.google.com/go/internal/version" - gax "github.com/googleapis/gax-go" - "golang.org/x/net/context" - "google.golang.org/api/iterator" - "google.golang.org/api/option" - "google.golang.org/api/transport" - pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" -) - -// SubscriberCallOptions contains the retry settings for each method of SubscriberClient. -type SubscriberCallOptions struct { - CreateSubscription []gax.CallOption - GetSubscription []gax.CallOption - UpdateSubscription []gax.CallOption - ListSubscriptions []gax.CallOption - DeleteSubscription []gax.CallOption - ModifyAckDeadline []gax.CallOption - Acknowledge []gax.CallOption - Pull []gax.CallOption - StreamingPull []gax.CallOption - ModifyPushConfig []gax.CallOption - ListSnapshots []gax.CallOption - CreateSnapshot []gax.CallOption - UpdateSnapshot []gax.CallOption - DeleteSnapshot []gax.CallOption - Seek []gax.CallOption -} - -func defaultSubscriberClientOptions() []option.ClientOption { - return []option.ClientOption{ - option.WithEndpoint("pubsub.googleapis.com:443"), - option.WithScopes(DefaultAuthScopes()...), - } -} - -func defaultSubscriberCallOptions() *SubscriberCallOptions { - retry := map[[2]string][]gax.CallOption{ - {"default", "idempotent"}: { - gax.WithRetry(func() gax.Retryer { - return gax.OnCodes([]codes.Code{ - codes.DeadlineExceeded, - codes.Unavailable, - }, gax.Backoff{ - Initial: 100 * time.Millisecond, - Max: 60000 * time.Millisecond, - Multiplier: 1.3, - }) - }), - }, - {"messaging", "pull"}: { - gax.WithRetry(func() gax.Retryer { - return gax.OnCodes([]codes.Code{ - codes.Canceled, - codes.DeadlineExceeded, - codes.Internal, - codes.ResourceExhausted, - codes.Unavailable, - }, gax.Backoff{ - Initial: 100 * time.Millisecond, - Max: 60000 * time.Millisecond, - Multiplier: 1.3, - }) - }), - }, - {"streaming_messaging", "pull"}: { - gax.WithRetry(func() gax.Retryer { - return gax.OnCodes([]codes.Code{ - codes.Canceled, - codes.DeadlineExceeded, - codes.Internal, - codes.ResourceExhausted, - codes.Unavailable, - }, gax.Backoff{ - Initial: 100 * time.Millisecond, - Max: 60000 * time.Millisecond, - Multiplier: 1.3, - }) - }), - }, - } - return &SubscriberCallOptions{ - CreateSubscription: retry[[2]string{"default", "idempotent"}], - GetSubscription: retry[[2]string{"default", "idempotent"}], - UpdateSubscription: retry[[2]string{"default", "idempotent"}], - ListSubscriptions: retry[[2]string{"default", "idempotent"}], - DeleteSubscription: retry[[2]string{"default", "idempotent"}], - ModifyAckDeadline: retry[[2]string{"default", "non_idempotent"}], - Acknowledge: retry[[2]string{"messaging", "non_idempotent"}], - Pull: retry[[2]string{"messaging", "pull"}], - StreamingPull: retry[[2]string{"streaming_messaging", "pull"}], - ModifyPushConfig: retry[[2]string{"default", "non_idempotent"}], - ListSnapshots: retry[[2]string{"default", "idempotent"}], - CreateSnapshot: retry[[2]string{"default", "idempotent"}], - UpdateSnapshot: retry[[2]string{"default", "idempotent"}], - DeleteSnapshot: retry[[2]string{"default", "idempotent"}], - Seek: retry[[2]string{"default", "non_idempotent"}], - } -} - -// SubscriberClient is a client for interacting with Google Cloud Pub/Sub API. -type SubscriberClient struct { - // The connection to the service. - conn *grpc.ClientConn - - // The gRPC API client. - subscriberClient pubsubpb.SubscriberClient - - // The call options for this service. - CallOptions *SubscriberCallOptions - - // The x-goog-* metadata to be sent with each request. - xGoogMetadata metadata.MD -} - -// NewSubscriberClient creates a new subscriber client. -// -// The service that an application uses to manipulate subscriptions and to -// consume messages from a subscription via the Pull method. -func NewSubscriberClient(ctx context.Context, opts ...option.ClientOption) (*SubscriberClient, error) { - conn, err := transport.DialGRPC(ctx, append(defaultSubscriberClientOptions(), opts...)...) - if err != nil { - return nil, err - } - c := &SubscriberClient{ - conn: conn, - CallOptions: defaultSubscriberCallOptions(), - - subscriberClient: pubsubpb.NewSubscriberClient(conn), - } - c.SetGoogleClientInfo() - return c, nil -} - -// Connection returns the client's connection to the API service. -func (c *SubscriberClient) Connection() *grpc.ClientConn { - return c.conn -} - -// Close closes the connection to the API service. The user should invoke this when -// the client is no longer required. -func (c *SubscriberClient) Close() error { - return c.conn.Close() -} - -// SetGoogleClientInfo sets the name and version of the application in -// the `x-goog-api-client` header passed on each request. Intended for -// use by Google-written clients. -func (c *SubscriberClient) SetGoogleClientInfo(keyval ...string) { - kv := append([]string{"gl-go", version.Go()}, keyval...) - kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", grpc.Version) - c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) -} - -func (c *SubscriberClient) SubscriptionIAM(subscription *pubsubpb.Subscription) *iam.Handle { - return iam.InternalNewHandle(c.Connection(), subscription.Name) -} - -func (c *SubscriberClient) TopicIAM(topic *pubsubpb.Topic) *iam.Handle { - return iam.InternalNewHandle(c.Connection(), topic.Name) -} - -// CreateSubscription creates a subscription to a given topic. -// If the subscription already exists, returns ALREADY_EXISTS. -// If the corresponding topic doesn't exist, returns NOT_FOUND. -// -// If the name is not provided in the request, the server will assign a random -// name for this subscription on the same project as the topic, conforming -// to the -// resource name format (at https://cloud.google.com/pubsub/docs/overview#names). -// The generated name is populated in the returned Subscription object. -// Note that for REST API requests, you must specify a name in the request. -func (c *SubscriberClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.CreateSubscription[0:len(c.CallOptions.CreateSubscription):len(c.CallOptions.CreateSubscription)], opts...) - var resp *pubsubpb.Subscription - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.CreateSubscription(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// GetSubscription gets the configuration details of a subscription. -func (c *SubscriberClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.GetSubscription[0:len(c.CallOptions.GetSubscription):len(c.CallOptions.GetSubscription)], opts...) - var resp *pubsubpb.Subscription - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.GetSubscription(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// UpdateSubscription updates an existing subscription. Note that certain properties of a -// subscription, such as its topic, are not modifiable. -// NOTE: The style guide requires body: "subscription" instead of body: "*". -// Keeping the latter for internal consistency in V1, however it should be -// corrected in V2. See -// https://cloud.google.com/apis/design/standard_methods#update for details. -func (c *SubscriberClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.UpdateSubscription[0:len(c.CallOptions.UpdateSubscription):len(c.CallOptions.UpdateSubscription)], opts...) - var resp *pubsubpb.Subscription - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.UpdateSubscription(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// ListSubscriptions lists matching subscriptions. -func (c *SubscriberClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIterator { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ListSubscriptions[0:len(c.CallOptions.ListSubscriptions):len(c.CallOptions.ListSubscriptions)], opts...) - it := &SubscriptionIterator{} - it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Subscription, string, error) { - var resp *pubsubpb.ListSubscriptionsResponse - req.PageToken = pageToken - if pageSize > math.MaxInt32 { - req.PageSize = math.MaxInt32 - } else { - req.PageSize = int32(pageSize) - } - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.ListSubscriptions(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, "", err - } - return resp.Subscriptions, resp.NextPageToken, nil - } - fetch := func(pageSize int, pageToken string) (string, error) { - items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) - if err != nil { - return "", err - } - it.items = append(it.items, items...) - return nextPageToken, nil - } - it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) - return it -} - -// DeleteSubscription deletes an existing subscription. All messages retained in the subscription -// are immediately dropped. Calls to Pull after deletion will return -// NOT_FOUND. After a subscription is deleted, a new one may be created with -// the same name, but the new one has no association with the old -// subscription or its topic unless the same topic is specified. -func (c *SubscriberClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.DeleteSubscription[0:len(c.CallOptions.DeleteSubscription):len(c.CallOptions.DeleteSubscription)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.subscriberClient.DeleteSubscription(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful -// to indicate that more time is needed to process a message by the -// subscriber, or to make the message available for redelivery if the -// processing was interrupted. Note that this does not modify the -// subscription-level ackDeadlineSeconds used for subsequent messages. -func (c *SubscriberClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ModifyAckDeadline[0:len(c.CallOptions.ModifyAckDeadline):len(c.CallOptions.ModifyAckDeadline)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.subscriberClient.ModifyAckDeadline(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// Acknowledge acknowledges the messages associated with the ack_ids in the -// AcknowledgeRequest. The Pub/Sub system can remove the relevant messages -// from the subscription. -// -// Acknowledging a message whose ack deadline has expired may succeed, -// but such a message may be redelivered later. Acknowledging a message more -// than once will not result in an error. -func (c *SubscriberClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.Acknowledge[0:len(c.CallOptions.Acknowledge):len(c.CallOptions.Acknowledge)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.subscriberClient.Acknowledge(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// Pull pulls messages from the server. Returns an empty list if there are no -// messages available in the backlog. The server may return UNAVAILABLE if -// there are too many concurrent pull requests pending for the given -// subscription. -func (c *SubscriberClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.Pull[0:len(c.CallOptions.Pull):len(c.CallOptions.Pull)], opts...) - var resp *pubsubpb.PullResponse - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.Pull(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// StreamingPull (EXPERIMENTAL) StreamingPull is an experimental feature. This RPC will -// respond with UNIMPLEMENTED errors unless you have been invited to test -// this feature. Contact cloud-pubsub@google.com with any questions. -// -// Establishes a stream with the server, which sends messages down to the -// client. The client streams acknowledgements and ack deadline modifications -// back to the server. The server will close the stream and return the status -// on any error. The server may close the stream with status OK to reassign -// server-side resources, in which case, the client should re-establish the -// stream. UNAVAILABLE may also be returned in the case of a transient error -// (e.g., a server restart). These should also be retried by the client. Flow -// control can be achieved by configuring the underlying RPC channel. -func (c *SubscriberClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.StreamingPull[0:len(c.CallOptions.StreamingPull):len(c.CallOptions.StreamingPull)], opts...) - var resp pubsubpb.Subscriber_StreamingPullClient - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.StreamingPull(ctx, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// ModifyPushConfig modifies the PushConfig for a specified subscription. -// -// This may be used to change a push subscription to a pull one (signified by -// an empty PushConfig) or vice versa, or change the endpoint URL and other -// attributes of a push subscription. Messages will accumulate for delivery -// continuously through the call regardless of changes to the PushConfig. -func (c *SubscriberClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ModifyPushConfig[0:len(c.CallOptions.ModifyPushConfig):len(c.CallOptions.ModifyPushConfig)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.subscriberClient.ModifyPushConfig(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// ListSnapshots lists the existing snapshots. -func (c *SubscriberClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIterator { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.ListSnapshots[0:len(c.CallOptions.ListSnapshots):len(c.CallOptions.ListSnapshots)], opts...) - it := &SnapshotIterator{} - it.InternalFetch = func(pageSize int, pageToken string) ([]*pubsubpb.Snapshot, string, error) { - var resp *pubsubpb.ListSnapshotsResponse - req.PageToken = pageToken - if pageSize > math.MaxInt32 { - req.PageSize = math.MaxInt32 - } else { - req.PageSize = int32(pageSize) - } - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.ListSnapshots(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, "", err - } - return resp.Snapshots, resp.NextPageToken, nil - } - fetch := func(pageSize int, pageToken string) (string, error) { - items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) - if err != nil { - return "", err - } - it.items = append(it.items, items...) - return nextPageToken, nil - } - it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) - return it -} - -// CreateSnapshot creates a snapshot from the requested subscription. -// If the snapshot already exists, returns ALREADY_EXISTS. -// If the requested subscription doesn't exist, returns NOT_FOUND. -// -// If the name is not provided in the request, the server will assign a random -// name for this snapshot on the same project as the subscription, conforming -// to the -// resource name format (at https://cloud.google.com/pubsub/docs/overview#names). -// The generated name is populated in the returned Snapshot object. -// Note that for REST API requests, you must specify a name in the request. -func (c *SubscriberClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.CreateSnapshot[0:len(c.CallOptions.CreateSnapshot):len(c.CallOptions.CreateSnapshot)], opts...) - var resp *pubsubpb.Snapshot - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.CreateSnapshot(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// UpdateSnapshot updates an existing snapshot. Note that certain properties of a snapshot -// are not modifiable. -// NOTE: The style guide requires body: "snapshot" instead of body: "*". -// Keeping the latter for internal consistency in V1, however it should be -// corrected in V2. See -// https://cloud.google.com/apis/design/standard_methods#update for details. -func (c *SubscriberClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.UpdateSnapshot[0:len(c.CallOptions.UpdateSnapshot):len(c.CallOptions.UpdateSnapshot)], opts...) - var resp *pubsubpb.Snapshot - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.UpdateSnapshot(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// DeleteSnapshot removes an existing snapshot. All messages retained in the snapshot -// are immediately dropped. After a snapshot is deleted, a new one may be -// created with the same name, but the new one has no association with the old -// snapshot or its subscription, unless the same subscription is specified. -func (c *SubscriberClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) error { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.DeleteSnapshot[0:len(c.CallOptions.DeleteSnapshot):len(c.CallOptions.DeleteSnapshot)], opts...) - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - _, err = c.subscriberClient.DeleteSnapshot(ctx, req, settings.GRPC...) - return err - }, opts...) - return err -} - -// Seek seeks an existing subscription to a point in time or to a given snapshot, -// whichever is provided in the request. -func (c *SubscriberClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error) { - ctx = insertMetadata(ctx, c.xGoogMetadata) - opts = append(c.CallOptions.Seek[0:len(c.CallOptions.Seek):len(c.CallOptions.Seek)], opts...) - var resp *pubsubpb.SeekResponse - err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { - var err error - resp, err = c.subscriberClient.Seek(ctx, req, settings.GRPC...) - return err - }, opts...) - if err != nil { - return nil, err - } - return resp, nil -} - -// SnapshotIterator manages a stream of *pubsubpb.Snapshot. -type SnapshotIterator struct { - items []*pubsubpb.Snapshot - pageInfo *iterator.PageInfo - nextFunc func() error - - // InternalFetch is for use by the Google Cloud Libraries only. - // It is not part of the stable interface of this package. - // - // InternalFetch returns results from a single call to the underlying RPC. - // The number of results is no greater than pageSize. - // If there are no more results, nextPageToken is empty and err is nil. - InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Snapshot, nextPageToken string, err error) -} - -// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. -func (it *SnapshotIterator) PageInfo() *iterator.PageInfo { - return it.pageInfo -} - -// Next returns the next result. Its second return value is iterator.Done if there are no more -// results. Once Next returns Done, all subsequent calls will return Done. -func (it *SnapshotIterator) Next() (*pubsubpb.Snapshot, error) { - var item *pubsubpb.Snapshot - if err := it.nextFunc(); err != nil { - return item, err - } - item = it.items[0] - it.items = it.items[1:] - return item, nil -} - -func (it *SnapshotIterator) bufLen() int { - return len(it.items) -} - -func (it *SnapshotIterator) takeBuf() interface{} { - b := it.items - it.items = nil - return b -} - -// SubscriptionIterator manages a stream of *pubsubpb.Subscription. -type SubscriptionIterator struct { - items []*pubsubpb.Subscription - pageInfo *iterator.PageInfo - nextFunc func() error - - // InternalFetch is for use by the Google Cloud Libraries only. - // It is not part of the stable interface of this package. - // - // InternalFetch returns results from a single call to the underlying RPC. - // The number of results is no greater than pageSize. - // If there are no more results, nextPageToken is empty and err is nil. - InternalFetch func(pageSize int, pageToken string) (results []*pubsubpb.Subscription, nextPageToken string, err error) -} - -// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. -func (it *SubscriptionIterator) PageInfo() *iterator.PageInfo { - return it.pageInfo -} - -// Next returns the next result. Its second return value is iterator.Done if there are no more -// results. Once Next returns Done, all subsequent calls will return Done. -func (it *SubscriptionIterator) Next() (*pubsubpb.Subscription, error) { - var item *pubsubpb.Subscription - if err := it.nextFunc(); err != nil { - return item, err - } - item = it.items[0] - it.items = it.items[1:] - return item, nil -} - -func (it *SubscriptionIterator) bufLen() int { - return len(it.items) -} - -func (it *SubscriptionIterator) takeBuf() interface{} { - b := it.items - it.items = nil - return b -} diff --git a/vendor/cloud.google.com/go/pubsub/doc.go b/vendor/cloud.google.com/go/pubsub/doc.go deleted file mode 100644 index 848b410e2e..0000000000 --- a/vendor/cloud.google.com/go/pubsub/doc.go +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub provides an easy way to publish and receive Google Cloud Pub/Sub -messages, hiding the the details of the underlying server RPCs. Google Cloud -Pub/Sub is a many-to-many, asynchronous messaging system that decouples senders -and receivers. - -Note: This package is in beta. Some backwards-incompatible changes may occur. - -More information about Google Cloud Pub/Sub is available at -https://cloud.google.com/pubsub/docs - -See https://godoc.org/cloud.google.com/go for authentication, timeouts, -connection pooling and similar aspects of this package. - - -Publishing - -Google Cloud Pub/Sub messages are published to topics. Topics may be created -using the pubsub package like so: - - topic, err := pubsubClient.CreateTopic(context.Background(), "topic-name") - -Messages may then be published to a topic: - - res := topic.Publish(ctx, &pubsub.Message{Data: []byte("payload")}) - -Publish queues the message for publishing and returns immediately. When enough -messages have accumulated, or enough time has elapsed, the batch of messages is -sent to the Pub/Sub service. - -Publish returns a PublishResult, which behaves like a future: its Get method -blocks until the message has been sent to the service. - -The first time you call Publish on a topic, goroutines are started in the -background. To clean up these goroutines, call Stop: - - topic.Stop() - -Receiving - -To receive messages published to a topic, clients create subscriptions -to the topic. There may be more than one subscription per topic; each message -that is published to the topic will be delivered to all of its subscriptions. - -Subsciptions may be created like so: - - sub, err := pubsubClient.CreateSubscription(context.Background(), "sub-name", - pubsub.SubscriptionConfig{Topic: topic}) - -Messages are then consumed from a subscription via callback. - - err := sub.Receive(context.Background(), func(ctx context.Context, m *Message) { - log.Printf("Got message: %s", m.Data) - m.Ack() - }) - if err != nil { - // Handle error. - } - -The callback is invoked concurrently by multiple goroutines, maximizing -throughput. To terminate a call to Receive, cancel its context. - -Once client code has processed the message, it must call Message.Ack, otherwise -the message will eventually be redelivered. As an optimization, if the client -cannot or doesn't want to process the message, it can call Message.Nack to -speed redelivery. For more information and configuration options, see -"Deadlines" below. - -Note: It is possible for Messages to be redelivered, even if Message.Ack has -been called. Client code must be robust to multiple deliveries of messages. - -Deadlines - -The default pubsub deadlines are suitable for most use cases, but may be -overridden. This section describes the tradeoffs that should be considered -when overriding the defaults. - -Behind the scenes, each message returned by the Pub/Sub server has an -associated lease, known as an "ACK deadline". -Unless a message is acknowledged within the ACK deadline, or the client requests that -the ACK deadline be extended, the message will become elegible for redelivery. -As a convenience, the pubsub package will automatically extend deadlines until -either: - * Message.Ack or Message.Nack is called, or - * the "MaxExtension" period elapses from the time the message is fetched from the server. - -The initial ACK deadline given to each messages defaults to 10 seconds, but may -be overridden during subscription creation. Selecting an ACK deadline is a -tradeoff between message redelivery latency and RPC volume. If the pubsub -package fails to acknowledge or extend a message (e.g. due to unexpected -termination of the process), a shorter ACK deadline will generally result in -faster message redelivery by the Pub/Sub system. However, a short ACK deadline -may also increase the number of deadline extension RPCs that the pubsub package -sends to the server. - -The default max extension period is DefaultReceiveSettings.MaxExtension, and can -be overridden by setting Subscription.ReceiveSettings.MaxExtension. Selecting a -max extension period is a tradeoff between the speed at which client code must -process messages, and the redelivery delay if messages fail to be acknowledged -(e.g. because client code neglects to do so). Using a large MaxExtension -increases the available time for client code to process messages. However, if -the client code neglects to call Message.Ack/Nack, a large MaxExtension will -increase the delay before the message is redelivered. - -Slow Message Processing - -For use cases where message processing exceeds 30 minutes, we recommend using -the base client in a pull model, since long-lived streams are periodically killed -by firewalls. See the example at https://godoc.org/cloud.google.com/go/pubsub/apiv1#example-SubscriberClient-Pull-LengthyClientProcessing -*/ -package pubsub // import "cloud.google.com/go/pubsub" diff --git a/vendor/cloud.google.com/go/pubsub/flow_controller.go b/vendor/cloud.google.com/go/pubsub/flow_controller.go deleted file mode 100644 index 0fd7bd6c83..0000000000 --- a/vendor/cloud.google.com/go/pubsub/flow_controller.go +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "golang.org/x/net/context" - "golang.org/x/sync/semaphore" -) - -// flowController implements flow control for Subscription.Receive. -type flowController struct { - maxSize int // max total size of messages - semCount, semSize *semaphore.Weighted // enforces max number and size of messages -} - -// newFlowController creates a new flowController that ensures no more than -// maxCount messages or maxSize bytes are outstanding at once. If maxCount or -// maxSize is < 1, then an unlimited number of messages or bytes is permitted, -// respectively. -func newFlowController(maxCount, maxSize int) *flowController { - fc := &flowController{ - maxSize: maxSize, - semCount: nil, - semSize: nil, - } - if maxCount > 0 { - fc.semCount = semaphore.NewWeighted(int64(maxCount)) - } - if maxSize > 0 { - fc.semSize = semaphore.NewWeighted(int64(maxSize)) - } - return fc -} - -// acquire blocks until one message of size bytes can proceed or ctx is done. -// It returns nil in the first case, or ctx.Err() in the second. -// -// acquire allows large messages to proceed by treating a size greater than maxSize -// as if it were equal to maxSize. -func (f *flowController) acquire(ctx context.Context, size int) error { - if f.semCount != nil { - if err := f.semCount.Acquire(ctx, 1); err != nil { - return err - } - } - if f.semSize != nil { - if err := f.semSize.Acquire(ctx, f.bound(size)); err != nil { - if f.semCount != nil { - f.semCount.Release(1) - } - return err - } - } - return nil -} - -// tryAcquire returns false if acquire would block. Otherwise, it behaves like -// acquire and returns true. -// -// tryAcquire allows large messages to proceed by treating a size greater than -// maxSize as if it were equal to maxSize. -func (f *flowController) tryAcquire(size int) bool { - if f.semCount != nil { - if !f.semCount.TryAcquire(1) { - return false - } - } - if f.semSize != nil { - if !f.semSize.TryAcquire(f.bound(size)) { - if f.semCount != nil { - f.semCount.Release(1) - } - return false - } - } - return true -} - -// release notes that one message of size bytes is no longer outstanding. -func (f *flowController) release(size int) { - if f.semCount != nil { - f.semCount.Release(1) - } - if f.semSize != nil { - f.semSize.Release(f.bound(size)) - } -} - -func (f *flowController) bound(size int) int64 { - if size > f.maxSize { - return int64(f.maxSize) - } - return int64(size) -} diff --git a/vendor/cloud.google.com/go/pubsub/go18.go b/vendor/cloud.google.com/go/pubsub/go18.go deleted file mode 100644 index 7a7229460a..0000000000 --- a/vendor/cloud.google.com/go/pubsub/go18.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2018 Google Inc. All Rights Reserved. -// -// 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. - -// +build go1.8 - -package pubsub - -import ( - "log" - "sync" - - "go.opencensus.io/plugin/ocgrpc" - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" - "golang.org/x/net/context" - "google.golang.org/api/option" - "google.golang.org/grpc" -) - -func openCensusOptions() []option.ClientOption { - return []option.ClientOption{ - option.WithGRPCDialOption(grpc.WithStatsHandler(&ocgrpc.ClientHandler{})), - } -} - -var subscriptionKey tag.Key - -func init() { - var err error - if subscriptionKey, err = tag.NewKey("subscription"); err != nil { - log.Fatal("cannot create 'subscription' key") - } -} - -const statsPrefix = "cloud.google.com/go/pubsub/" - -var ( - // PullCount is a measure of the number of messages pulled. - // It is EXPERIMENTAL and subject to change or removal without notice. - PullCount = stats.Int64(statsPrefix+"pull_count", "Number of PubSub messages pulled", stats.UnitNone) - - // AckCount is a measure of the number of messages acked. - // It is EXPERIMENTAL and subject to change or removal without notice. - AckCount = stats.Int64(statsPrefix+"ack_count", "Number of PubSub messages acked", stats.UnitNone) - - // NackCount is a measure of the number of messages nacked. - // It is EXPERIMENTAL and subject to change or removal without notice. - NackCount = stats.Int64(statsPrefix+"nack_count", "Number of PubSub messages nacked", stats.UnitNone) - - // ModAckCount is a measure of the number of messages whose ack-deadline was modified. - // It is EXPERIMENTAL and subject to change or removal without notice. - ModAckCount = stats.Int64(statsPrefix+"mod_ack_count", "Number of ack-deadlines modified", stats.UnitNone) - - // StreamOpenCount is a measure of the number of times a streaming-pull stream was opened. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamOpenCount = stats.Int64(statsPrefix+"stream_open_count", "Number of calls opening a new streaming pull", stats.UnitNone) - - // StreamRetryCount is a measure of the number of times a streaming-pull operation was retried. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamRetryCount = stats.Int64(statsPrefix+"stream_retry_count", "Number of retries of a stream send or receive", stats.UnitNone) - - // StreamRequestCount is a measure of the number of requests sent on a streaming-pull stream. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamRequestCount = stats.Int64(statsPrefix+"stream_request_count", "Number gRPC StreamingPull request messages sent", stats.UnitNone) - - // StreamResponseCount is a measure of the number of responses received on a streaming-pull stream. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamResponseCount = stats.Int64(statsPrefix+"stream_response_count", "Number of gRPC StreamingPull response messages received", stats.UnitNone) - - // PullCountView is a cumulative sum of PullCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - PullCountView *view.View - - // AckCountView is a cumulative sum of AckCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - AckCountView *view.View - - // NackCountView is a cumulative sum of NackCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - NackCountView *view.View - - // ModAckCountView is a cumulative sum of ModAckCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - ModAckCountView *view.View - - // StreamOpenCountView is a cumulative sum of StreamOpenCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamOpenCountView *view.View - - // StreamRetryCountView is a cumulative sum of StreamRetryCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamRetryCountView *view.View - - // StreamRequestCountView is a cumulative sum of StreamRequestCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamRequestCountView *view.View - - // StreamResponseCountView is a cumulative sum of StreamResponseCount. - // It is EXPERIMENTAL and subject to change or removal without notice. - StreamResponseCountView *view.View -) - -func init() { - PullCountView = countView(PullCount) - AckCountView = countView(AckCount) - NackCountView = countView(NackCount) - ModAckCountView = countView(ModAckCount) - StreamOpenCountView = countView(StreamOpenCount) - StreamRetryCountView = countView(StreamRetryCount) - StreamRequestCountView = countView(StreamRequestCount) - StreamResponseCountView = countView(StreamResponseCount) -} - -func countView(m *stats.Int64Measure) *view.View { - return &view.View{ - Name: m.Name(), - Description: m.Description(), - TagKeys: []tag.Key{subscriptionKey}, - Measure: m, - Aggregation: view.Sum(), - } -} - -var logOnce sync.Once - -func withSubscriptionKey(ctx context.Context, subName string) context.Context { - ctx, err := tag.New(ctx, tag.Upsert(subscriptionKey, subName)) - if err != nil { - logOnce.Do(func() { - log.Printf("pubsub: error creating tag map: %v", err) - }) - } - return ctx -} - -func recordStat(ctx context.Context, m *stats.Int64Measure, n int64) { - stats.Record(ctx, m.M(n)) -} diff --git a/vendor/cloud.google.com/go/pubsub/internal/distribution/distribution.go b/vendor/cloud.google.com/go/pubsub/internal/distribution/distribution.go deleted file mode 100644 index c13fd636c7..0000000000 --- a/vendor/cloud.google.com/go/pubsub/internal/distribution/distribution.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 distribution - -import ( - "log" - "math" - "sort" - "sync/atomic" -) - -// D is a distribution. Methods of D can be called concurrently by multiple -// goroutines. -type D struct { - buckets []uint64 -} - -// New creates a new distribution capable of holding values from 0 to n-1. -func New(n int) *D { - return &D{ - buckets: make([]uint64, n), - } -} - -// Record records value v to the distribution. -// To help with distributions with long tails, if v is larger than the maximum value, -// Record records the maximum value instead. -// If v is negative, Record panics. -func (d *D) Record(v int) { - if v < 0 { - log.Panicf("Record: value out of range: %d", v) - } else if v >= len(d.buckets) { - v = len(d.buckets) - 1 - } - atomic.AddUint64(&d.buckets[v], 1) -} - -// Percentile computes the p-th percentile of the distribution where -// p is between 0 and 1. -func (d *D) Percentile(p float64) int { - // NOTE: This implementation uses the nearest-rank method. - // https://en.wikipedia.org/wiki/Percentile#The_nearest-rank_method - - if p < 0 || p > 1 { - log.Panicf("Percentile: percentile out of range: %f", p) - } - - bucketSums := make([]uint64, len(d.buckets)) - var sum uint64 - for i := range bucketSums { - sum += atomic.LoadUint64(&d.buckets[i]) - bucketSums[i] = sum - } - - total := bucketSums[len(bucketSums)-1] - target := uint64(math.Ceil(float64(total) * p)) - return sort.Search(len(bucketSums), func(i int) bool { return bucketSums[i] >= target }) -} diff --git a/vendor/cloud.google.com/go/pubsub/iterator.go b/vendor/cloud.google.com/go/pubsub/iterator.go deleted file mode 100644 index 78934e2c89..0000000000 --- a/vendor/cloud.google.com/go/pubsub/iterator.go +++ /dev/null @@ -1,294 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "sync" - "time" - - vkit "cloud.google.com/go/pubsub/apiv1" - "cloud.google.com/go/pubsub/internal/distribution" - "golang.org/x/net/context" - pb "google.golang.org/genproto/googleapis/pubsub/v1" -) - -// newMessageIterator starts a new streamingMessageIterator. Stop must be called on the messageIterator -// when it is no longer needed. -// subName is the full name of the subscription to pull messages from. -// ctx is the context to use for acking messages and extending message deadlines. -func newMessageIterator(ctx context.Context, subc *vkit.SubscriberClient, subName string, po *pullOptions) *streamingMessageIterator { - ps := newPullStream(ctx, subc, subName, int32(po.ackDeadline.Seconds())) - return newStreamingMessageIterator(ctx, ps, po) -} - -type streamingMessageIterator struct { - ctx context.Context - po *pullOptions - ps *pullStream - kaTicker *time.Ticker // keep-alive (deadline extensions) - ackTicker *time.Ticker // message acks - nackTicker *time.Ticker // message nacks (more frequent than acks) - failed chan struct{} // closed on stream error - stopped chan struct{} // closed when Stop is called - drained chan struct{} // closed when stopped && no more pending messages - wg sync.WaitGroup - - mu sync.Mutex - ackTimeDist *distribution.D - keepAliveDeadlines map[string]time.Time - pendingReq *pb.StreamingPullRequest - pendingModAcks map[string]int32 // ack IDs whose ack deadline is to be modified - err error // error from stream failure -} - -func newStreamingMessageIterator(ctx context.Context, ps *pullStream, po *pullOptions) *streamingMessageIterator { - // TODO: make kaTicker frequency more configurable. (ackDeadline - 5s) is a - // reasonable default for now, because the minimum ack period is 10s. This - // gives us 5s grace. - keepAlivePeriod := po.ackDeadline - 5*time.Second - kaTicker := time.NewTicker(keepAlivePeriod) - - // Ack promptly so users don't lose work if client crashes. - ackTicker := time.NewTicker(100 * time.Millisecond) - nackTicker := time.NewTicker(100 * time.Millisecond) - it := &streamingMessageIterator{ - ctx: ctx, - ps: ps, - po: po, - kaTicker: kaTicker, - ackTicker: ackTicker, - nackTicker: nackTicker, - failed: make(chan struct{}), - stopped: make(chan struct{}), - drained: make(chan struct{}), - ackTimeDist: distribution.New(int(maxAckDeadline/time.Second) + 1), - keepAliveDeadlines: map[string]time.Time{}, - pendingReq: &pb.StreamingPullRequest{}, - pendingModAcks: map[string]int32{}, - } - it.wg.Add(1) - go it.sender() - return it -} - -// Subscription.receive will call stop on its messageIterator when finished with it. -// Stop will block until Done has been called on all Messages that have been -// returned by Next, or until the context with which the messageIterator was created -// is cancelled or exceeds its deadline. -func (it *streamingMessageIterator) stop() { - it.mu.Lock() - select { - case <-it.stopped: - default: - close(it.stopped) - } - it.checkDrained() - it.mu.Unlock() - it.wg.Wait() -} - -// checkDrained closes the drained channel if the iterator has been stopped and all -// pending messages have either been n/acked or expired. -// -// Called with the lock held. -func (it *streamingMessageIterator) checkDrained() { - select { - case <-it.drained: - return - default: - } - select { - case <-it.stopped: - if len(it.keepAliveDeadlines) == 0 { - close(it.drained) - } - default: - } -} - -// Called when a message is acked/nacked. -func (it *streamingMessageIterator) done(ackID string, ack bool, receiveTime time.Time) { - it.ackTimeDist.Record(int(time.Since(receiveTime) / time.Second)) - it.mu.Lock() - defer it.mu.Unlock() - delete(it.keepAliveDeadlines, ackID) - if ack { - it.pendingReq.AckIds = append(it.pendingReq.AckIds, ackID) - } else { - it.pendingModAcks[ackID] = 0 // Nack indicated by modifying the deadline to zero. - } - it.checkDrained() -} - -// fail is called when a stream method returns a permanent error. -func (it *streamingMessageIterator) fail(err error) { - it.mu.Lock() - if it.err == nil { - it.err = err - close(it.failed) - } - it.mu.Unlock() -} - -// receive makes a call to the stream's Recv method and returns -// its messages. -func (it *streamingMessageIterator) receive() ([]*Message, error) { - // Stop retrieving messages if the context is done, the stream - // failed, or the iterator's Stop method was called. - select { - case <-it.ctx.Done(): - return nil, it.ctx.Err() - default: - } - it.mu.Lock() - err := it.err - it.mu.Unlock() - if err != nil { - return nil, err - } - // Receive messages from stream. This may block indefinitely. - res, err := it.ps.Recv() - // The pullStream handles retries, so any error here is fatal. - if err != nil { - it.fail(err) - return nil, err - } - msgs, err := convertMessages(res.ReceivedMessages) - if err != nil { - it.fail(err) - return nil, err - } - - // We received some messages. Remember them so we can keep them alive. Also, - // arrange for a receipt mod-ack (which will occur at the next firing of - // nackTicker). - maxExt := time.Now().Add(it.po.maxExtension) - deadline := trunc32(int64(it.po.ackDeadline.Seconds())) - it.mu.Lock() - now := time.Now() - for _, m := range msgs { - m.receiveTime = now - m.doneFunc = it.done - it.keepAliveDeadlines[m.ackID] = maxExt - // The receipt mod-ack uses the subscription's configured ack deadline. Don't - // change the mod-ack if one is already pending. This is possible if there - // are retries. - if _, ok := it.pendingModAcks[m.ackID]; !ok { - it.pendingModAcks[m.ackID] = deadline - } - } - it.mu.Unlock() - return msgs, nil -} - -// sender runs in a goroutine and handles all sends to the stream. -func (it *streamingMessageIterator) sender() { - defer it.wg.Done() - defer it.kaTicker.Stop() - defer it.ackTicker.Stop() - defer it.nackTicker.Stop() - defer it.ps.CloseSend() - - done := false - for !done { - send := false - select { - case <-it.ctx.Done(): - // Context canceled or timed out: stop immediately, without - // another RPC. - return - - case <-it.failed: - // Stream failed: nothing to do, so stop immediately. - return - - case <-it.drained: - // All outstanding messages have been marked done: - // nothing left to do except send the final request. - it.mu.Lock() - send = (len(it.pendingReq.AckIds) > 0 || len(it.pendingModAcks) > 0) - done = true - - case <-it.kaTicker.C: - it.mu.Lock() - it.handleKeepAlives() - send = (len(it.pendingModAcks) > 0) - - case <-it.nackTicker.C: - it.mu.Lock() - send = (len(it.pendingModAcks) > 0) - - case <-it.ackTicker.C: - it.mu.Lock() - send = (len(it.pendingReq.AckIds) > 0) - } - // Lock is held here. - if send { - req := it.pendingReq - it.pendingReq = &pb.StreamingPullRequest{} - modAcks := it.pendingModAcks - it.pendingModAcks = map[string]int32{} - it.mu.Unlock() - for id, s := range modAcks { - req.ModifyDeadlineAckIds = append(req.ModifyDeadlineAckIds, id) - req.ModifyDeadlineSeconds = append(req.ModifyDeadlineSeconds, s) - } - err := it.send(req) - if err != nil { - // The streamingPuller handles retries, so any error here - // is fatal to the iterator. - it.fail(err) - return - } - } else { - it.mu.Unlock() - } - } -} - -func (it *streamingMessageIterator) send(req *pb.StreamingPullRequest) error { - // Note: len(modAckIDs) == len(modSecs) - var rest *pb.StreamingPullRequest - for len(req.AckIds) > 0 || len(req.ModifyDeadlineAckIds) > 0 { - req, rest = splitRequest(req, maxPayload) - if err := it.ps.Send(req); err != nil { - return err - } - req = rest - } - return nil -} - -// handleKeepAlives modifies the pending request to include deadline extensions -// for live messages. It also purges expired messages. -// -// Called with the lock held. -func (it *streamingMessageIterator) handleKeepAlives() { - now := time.Now() - dl := trunc32(int64(it.po.ackDeadline.Seconds())) - for id, expiry := range it.keepAliveDeadlines { - if expiry.Before(now) { - // This delete will not result in skipping any map items, as implied by - // the spec at https://golang.org/ref/spec#For_statements, "For - // statements with range clause", note 3, and stated explicitly at - // https://groups.google.com/forum/#!msg/golang-nuts/UciASUb03Js/pzSq5iVFAQAJ. - delete(it.keepAliveDeadlines, id) - } else { - // This will not overwrite a nack, because nacking removes the ID from keepAliveDeadlines. - it.pendingModAcks[id] = dl - } - } - it.checkDrained() -} diff --git a/vendor/cloud.google.com/go/pubsub/message.go b/vendor/cloud.google.com/go/pubsub/message.go deleted file mode 100644 index ac2cecca32..0000000000 --- a/vendor/cloud.google.com/go/pubsub/message.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "time" - - "github.com/golang/protobuf/ptypes" - pb "google.golang.org/genproto/googleapis/pubsub/v1" -) - -// Message represents a Pub/Sub message. -type Message struct { - // ID identifies this message. - // This ID is assigned by the server and is populated for Messages obtained from a subscription. - // This field is read-only. - ID string - - // Data is the actual data in the message. - Data []byte - - // Attributes represents the key-value pairs the current message - // is labelled with. - Attributes map[string]string - - // ackID is the identifier to acknowledge this message. - ackID string - - // The time at which the message was published. - // This is populated by the server for Messages obtained from a subscription. - // This field is read-only. - PublishTime time.Time - - // receiveTime is the time the message was received by the client. - receiveTime time.Time - - // size is the approximate size of the message's data and attributes. - size int - - calledDone bool - - // The done method of the iterator that created this Message. - doneFunc func(string, bool, time.Time) -} - -func toMessage(resp *pb.ReceivedMessage) (*Message, error) { - if resp.Message == nil { - return &Message{ackID: resp.AckId}, nil - } - - pubTime, err := ptypes.Timestamp(resp.Message.PublishTime) - if err != nil { - return nil, err - } - return &Message{ - ackID: resp.AckId, - Data: resp.Message.Data, - Attributes: resp.Message.Attributes, - ID: resp.Message.MessageId, - PublishTime: pubTime, - }, nil -} - -// Ack indicates successful processing of a Message passed to the Subscriber.Receive callback. -// It should not be called on any other Message value. -// If message acknowledgement fails, the Message will be redelivered. -// Client code must call Ack or Nack when finished for each received Message. -// Calls to Ack or Nack have no effect after the first call. -func (m *Message) Ack() { - m.done(true) -} - -// Nack indicates that the client will not or cannot process a Message passed to the Subscriber.Receive callback. -// It should not be called on any other Message value. -// Nack will result in the Message being redelivered more quickly than if it were allowed to expire. -// Client code must call Ack or Nack when finished for each received Message. -// Calls to Ack or Nack have no effect after the first call. -func (m *Message) Nack() { - m.done(false) -} - -func (m *Message) done(ack bool) { - if m.calledDone { - return - } - m.calledDone = true - m.doneFunc(m.ackID, ack, m.receiveTime) -} diff --git a/vendor/cloud.google.com/go/pubsub/not_go18.go b/vendor/cloud.google.com/go/pubsub/not_go18.go deleted file mode 100644 index 09fd4bf580..0000000000 --- a/vendor/cloud.google.com/go/pubsub/not_go18.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2018 Google Inc. All Rights Reserved. -// -// 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. - -// +build !go1.8 - -package pubsub - -import ( - "golang.org/x/net/context" - "google.golang.org/api/option" -) - -// OpenCensus only supports go 1.8 and higher. - -func openCensusOptions() []option.ClientOption { return nil } - -func withSubscriptionKey(ctx context.Context, _ string) context.Context { - return ctx -} - -type dummy struct{} - -var ( - // Not supported below Go 1.8. - PullCount dummy - // Not supported below Go 1.8. - AckCount dummy - // Not supported below Go 1.8. - NackCount dummy - // Not supported below Go 1.8. - ModAckCount dummy - // Not supported below Go 1.8. - StreamOpenCount dummy - // Not supported below Go 1.8. - StreamRetryCount dummy - // Not supported below Go 1.8. - StreamRequestCount dummy - // Not supported below Go 1.8. - StreamResponseCount dummy -) - -func recordStat(context.Context, dummy, int64) { -} diff --git a/vendor/cloud.google.com/go/pubsub/pubsub.go b/vendor/cloud.google.com/go/pubsub/pubsub.go deleted file mode 100644 index 8475186d73..0000000000 --- a/vendor/cloud.google.com/go/pubsub/pubsub.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2014 Google Inc. All Rights Reserved. -// -// 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 pubsub // import "cloud.google.com/go/pubsub" - -import ( - "fmt" - "os" - "runtime" - "time" - - "cloud.google.com/go/internal/version" - vkit "cloud.google.com/go/pubsub/apiv1" - "golang.org/x/net/context" - "google.golang.org/api/option" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" -) - -const ( - // ScopePubSub grants permissions to view and manage Pub/Sub - // topics and subscriptions. - ScopePubSub = "https://www.googleapis.com/auth/pubsub" - - // ScopeCloudPlatform grants permissions to view and manage your data - // across Google Cloud Platform services. - ScopeCloudPlatform = "https://www.googleapis.com/auth/cloud-platform" -) - -const ( - prodAddr = "https://pubsub.googleapis.com/" - minAckDeadline = 10 * time.Second - maxAckDeadline = 10 * time.Minute -) - -// Client is a Google Pub/Sub client scoped to a single project. -// -// Clients should be reused rather than being created as needed. -// A Client may be shared by multiple goroutines. -type Client struct { - projectID string - pubc *vkit.PublisherClient - subc *vkit.SubscriberClient -} - -// NewClient creates a new PubSub client. -func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (c *Client, err error) { - var o []option.ClientOption - // Environment variables for gcloud emulator: - // https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/ - if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" { - conn, err := grpc.Dial(addr, grpc.WithInsecure()) - if err != nil { - return nil, fmt.Errorf("grpc.Dial: %v", err) - } - o = []option.ClientOption{option.WithGRPCConn(conn)} - } else { - o = []option.ClientOption{ - // Create multiple connections to increase throughput. - option.WithGRPCConnectionPool(runtime.GOMAXPROCS(0)), - option.WithGRPCDialOption(grpc.WithKeepaliveParams(keepalive.ClientParameters{ - Time: 5 * time.Minute, - })), - } - o = append(o, openCensusOptions()...) - } - o = append(o, opts...) - pubc, err := vkit.NewPublisherClient(ctx, o...) - if err != nil { - return nil, fmt.Errorf("pubsub: %v", err) - } - subc, err := vkit.NewSubscriberClient(ctx, option.WithGRPCConn(pubc.Connection())) - if err != nil { - // Should never happen, since we are passing in the connection. - // If it does, we cannot close, because the user may have passed in their - // own connection originally. - return nil, fmt.Errorf("pubsub: %v", err) - } - pubc.SetGoogleClientInfo("gccl", version.Repo) - subc.SetGoogleClientInfo("gccl", version.Repo) - return &Client{ - projectID: projectID, - pubc: pubc, - subc: subc, - }, nil -} - -// Close releases any resources held by the client, -// such as memory and goroutines. -// -// If the client is available for the lifetime of the program, then Close need not be -// called at exit. -func (c *Client) Close() error { - // Return the first error, because the first call closes the connection. - err := c.pubc.Close() - _ = c.subc.Close() - return err -} - -func (c *Client) fullyQualifiedProjectName() string { - return fmt.Sprintf("projects/%s", c.projectID) -} diff --git a/vendor/cloud.google.com/go/pubsub/pullstream.go b/vendor/cloud.google.com/go/pubsub/pullstream.go deleted file mode 100644 index 4aea1d501b..0000000000 --- a/vendor/cloud.google.com/go/pubsub/pullstream.go +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2018 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "io" - "sync" - "time" - - vkit "cloud.google.com/go/pubsub/apiv1" - gax "github.com/googleapis/gax-go" - "golang.org/x/net/context" - pb "google.golang.org/genproto/googleapis/pubsub/v1" - "google.golang.org/grpc" -) - -// A pullStream supports the methods of a StreamingPullClient, but re-opens -// the stream on a retryable error. -type pullStream struct { - ctx context.Context - open func() (pb.Subscriber_StreamingPullClient, error) - - mu sync.Mutex - spc *pb.Subscriber_StreamingPullClient - err error // permanent error -} - -func newPullStream(ctx context.Context, subc *vkit.SubscriberClient, subName string, ackDeadlineSecs int32) *pullStream { - ctx = withSubscriptionKey(ctx, subName) - return &pullStream{ - ctx: ctx, - open: func() (pb.Subscriber_StreamingPullClient, error) { - spc, err := subc.StreamingPull(ctx, gax.WithGRPCOptions(grpc.MaxCallRecvMsgSize(maxSendRecvBytes))) - if err == nil { - recordStat(ctx, StreamRequestCount, 1) - err = spc.Send(&pb.StreamingPullRequest{ - Subscription: subName, - StreamAckDeadlineSeconds: ackDeadlineSecs, - }) - } - if err != nil { - return nil, err - } - return spc, nil - }, - } -} - -// get returns either a valid *StreamingPullClient (SPC), or a permanent error. -// If the argument is nil, this is the first call for an RPC, and the current -// SPC will be returned (or a new one will be opened). Otherwise, this call is a -// request to re-open the stream because of a retryable error, and the argument -// is a pointer to the SPC that returned the error. -func (s *pullStream) get(spc *pb.Subscriber_StreamingPullClient) (*pb.Subscriber_StreamingPullClient, error) { - s.mu.Lock() - defer s.mu.Unlock() - // A stored error is permanent. - if s.err != nil { - return nil, s.err - } - // If the context is done, so are we. - select { - case <-s.ctx.Done(): - s.err = s.ctx.Err() - return nil, s.err - default: - } - // TODO(jba): We can use the following instead of the above after we drop support for 1.8: - // s.err = s.ctx.Err() - // if s.err != nil { - // return nil, s.err - // } - - // If the current and argument SPCs differ, return the current one. This subsumes two cases: - // 1. We have an SPC and the caller is getting the stream for the first time. - // 2. The caller wants to retry, but they have an older SPC; we've already retried. - if spc != s.spc { - return s.spc, nil - } - // Either this is the very first call on this stream (s.spc == nil), or we have a valid - // retry request. Either way, open a new stream. - // The lock is held here for a long time, but it doesn't matter because no callers could get - // anything done anyway. - s.spc = new(pb.Subscriber_StreamingPullClient) - recordStat(s.ctx, StreamOpenCount, 1) - *s.spc, s.err = s.open() // Setting s.err means any error from open is permanent. Reconsider. - return s.spc, s.err -} - -func (s *pullStream) call(f func(pb.Subscriber_StreamingPullClient) error) error { - var ( - spc *pb.Subscriber_StreamingPullClient - err error - bo gax.Backoff - ) - for i := 0; ; i++ { - spc, err = s.get(spc) - if err != nil { - // Preserve the existing behavior of not retrying on open. Is that a bug? - // (If we do decide to retry, don't retry after we're closed.) - return err - } - start := time.Now() - err = f(*spc) - if err != nil { - if isRetryable(err) { - recordStat(s.ctx, StreamRetryCount, 1) - if time.Since(start) < 30*time.Second { // don't sleep if we've been blocked for a while - if err := gax.Sleep(s.ctx, bo.Pause()); err != nil { - return err - } - } - continue - } - s.mu.Lock() - s.err = err - s.mu.Unlock() - } - return err - } -} - -func (s *pullStream) Send(req *pb.StreamingPullRequest) error { - return s.call(func(spc pb.Subscriber_StreamingPullClient) error { - recordStat(s.ctx, AckCount, int64(len(req.AckIds))) - zeroes := 0 - for _, mds := range req.ModifyDeadlineSeconds { - if mds == 0 { - zeroes++ - } - } - recordStat(s.ctx, NackCount, int64(zeroes)) - recordStat(s.ctx, ModAckCount, int64(len(req.ModifyDeadlineSeconds)-zeroes)) - recordStat(s.ctx, StreamRequestCount, 1) - return spc.Send(req) - }) -} - -func (s *pullStream) Recv() (*pb.StreamingPullResponse, error) { - var res *pb.StreamingPullResponse - err := s.call(func(spc pb.Subscriber_StreamingPullClient) error { - var err error - recordStat(s.ctx, StreamResponseCount, 1) - res, err = spc.Recv() - if err == nil { - recordStat(s.ctx, PullCount, int64(len(res.ReceivedMessages))) - } - return err - }) - return res, err -} - -func (s *pullStream) CloseSend() error { - err := s.call(func(spc pb.Subscriber_StreamingPullClient) error { - return spc.CloseSend() - }) - s.mu.Lock() - s.err = io.EOF // should not be retried - s.mu.Unlock() - return err -} diff --git a/vendor/cloud.google.com/go/pubsub/service.go b/vendor/cloud.google.com/go/pubsub/service.go deleted file mode 100644 index c63e4d92dc..0000000000 --- a/vendor/cloud.google.com/go/pubsub/service.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "fmt" - "math" - "strings" - - pb "google.golang.org/genproto/googleapis/pubsub/v1" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" -) - -// maxPayload is the maximum number of bytes to devote to actual ids in -// acknowledgement or modifyAckDeadline requests. A serialized -// AcknowledgeRequest proto has a small constant overhead, plus the size of the -// subscription name, plus 3 bytes per ID (a tag byte and two size bytes). A -// ModifyAckDeadlineRequest has an additional few bytes for the deadline. We -// don't know the subscription name here, so we just assume the size exclusive -// of ids is 100 bytes. -// -// With gRPC there is no way for the client to know the server's max message size (it is -// configurable on the server). We know from experience that it -// it 512K. -const ( - maxPayload = 512 * 1024 - reqFixedOverhead = 100 - overheadPerID = 3 - maxSendRecvBytes = 20 * 1024 * 1024 // 20M -) - -func convertMessages(rms []*pb.ReceivedMessage) ([]*Message, error) { - msgs := make([]*Message, 0, len(rms)) - for i, m := range rms { - msg, err := toMessage(m) - if err != nil { - return nil, fmt.Errorf("pubsub: cannot decode the retrieved message at index: %d, message: %+v", i, m) - } - msgs = append(msgs, msg) - } - return msgs, nil -} - -func trunc32(i int64) int32 { - if i > math.MaxInt32 { - i = math.MaxInt32 - } - return int32(i) -} - -// Logic from https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/StatusUtil.java. -func isRetryable(err error) bool { - s, ok := status.FromError(err) - if !ok { // includes io.EOF, normal stream close, which causes us to reopen - return true - } - switch s.Code() { - case codes.DeadlineExceeded, codes.Internal, codes.Canceled, codes.ResourceExhausted: - return true - case codes.Unavailable: - return !strings.Contains(s.Message(), "Server shutdownNow invoked") - default: - return false - } -} - -// Split req into a prefix that is smaller than maxSize, and a remainder. -func splitRequest(req *pb.StreamingPullRequest, maxSize int) (prefix, remainder *pb.StreamingPullRequest) { - const int32Bytes = 4 - - // Copy all fields before splitting the variable-sized ones. - remainder = &pb.StreamingPullRequest{} - *remainder = *req - // Split message so it isn't too big. - size := reqFixedOverhead - i := 0 - for size < maxSize && (i < len(req.AckIds) || i < len(req.ModifyDeadlineAckIds)) { - if i < len(req.AckIds) { - size += overheadPerID + len(req.AckIds[i]) - } - if i < len(req.ModifyDeadlineAckIds) { - size += overheadPerID + len(req.ModifyDeadlineAckIds[i]) + int32Bytes - } - i++ - } - - min := func(a, b int) int { - if a < b { - return a - } - return b - } - - j := i - if size > maxSize { - j-- - } - k := min(j, len(req.AckIds)) - remainder.AckIds = req.AckIds[k:] - req.AckIds = req.AckIds[:k] - k = min(j, len(req.ModifyDeadlineAckIds)) - remainder.ModifyDeadlineAckIds = req.ModifyDeadlineAckIds[k:] - remainder.ModifyDeadlineSeconds = req.ModifyDeadlineSeconds[k:] - req.ModifyDeadlineAckIds = req.ModifyDeadlineAckIds[:k] - req.ModifyDeadlineSeconds = req.ModifyDeadlineSeconds[:k] - return req, remainder -} diff --git a/vendor/cloud.google.com/go/pubsub/snapshot.go b/vendor/cloud.google.com/go/pubsub/snapshot.go deleted file mode 100644 index 7140e96627..0000000000 --- a/vendor/cloud.google.com/go/pubsub/snapshot.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "fmt" - "strings" - "time" - - "github.com/golang/protobuf/ptypes" - "golang.org/x/net/context" - pb "google.golang.org/genproto/googleapis/pubsub/v1" -) - -// Snapshot is a reference to a PubSub snapshot. -type Snapshot struct { - c *Client - - // The fully qualified identifier for the snapshot, in the format "projects//snapshots/" - name string -} - -// ID returns the unique identifier of the snapshot within its project. -func (s *Snapshot) ID() string { - slash := strings.LastIndex(s.name, "/") - if slash == -1 { - // name is not a fully-qualified name. - panic("bad snapshot name") - } - return s.name[slash+1:] -} - -// SnapshotConfig contains the details of a Snapshot. -type SnapshotConfig struct { - *Snapshot - Topic *Topic - Expiration time.Time -} - -// Snapshot creates a reference to a snapshot. -func (c *Client) Snapshot(id string) *Snapshot { - return &Snapshot{ - c: c, - name: fmt.Sprintf("projects/%s/snapshots/%s", c.projectID, id), - } -} - -// Snapshots returns an iterator which returns snapshots for this project. -func (c *Client) Snapshots(ctx context.Context) *SnapshotConfigIterator { - it := c.subc.ListSnapshots(ctx, &pb.ListSnapshotsRequest{ - Project: c.fullyQualifiedProjectName(), - }) - next := func() (*SnapshotConfig, error) { - snap, err := it.Next() - if err != nil { - return nil, err - } - return toSnapshotConfig(snap, c) - } - return &SnapshotConfigIterator{next: next} -} - -// SnapshotConfigIterator is an iterator that returns a series of snapshots. -type SnapshotConfigIterator struct { - next func() (*SnapshotConfig, error) -} - -// Next returns the next SnapshotConfig. Its second return value is iterator.Done if there are no more results. -// Once Next returns iterator.Done, all subsequent calls will return iterator.Done. -func (snaps *SnapshotConfigIterator) Next() (*SnapshotConfig, error) { - return snaps.next() -} - -// Delete deletes a snapshot. -func (snap *Snapshot) Delete(ctx context.Context) error { - return snap.c.subc.DeleteSnapshot(ctx, &pb.DeleteSnapshotRequest{Snapshot: snap.name}) -} - -// SeekToTime seeks the subscription to a point in time. -// -// Messages retained in the subscription that were published before this -// time are marked as acknowledged, and messages retained in the -// subscription that were published after this time are marked as -// unacknowledged. Note that this operation affects only those messages -// retained in the subscription (configured by SnapshotConfig). For example, -// if `time` corresponds to a point before the message retention -// window (or to a point before the system's notion of the subscription -// creation time), only retained messages will be marked as unacknowledged, -// and already-expunged messages will not be restored. -func (s *Subscription) SeekToTime(ctx context.Context, t time.Time) error { - ts, err := ptypes.TimestampProto(t) - if err != nil { - return err - } - _, err = s.c.subc.Seek(ctx, &pb.SeekRequest{ - Subscription: s.name, - Target: &pb.SeekRequest_Time{ts}, - }) - return err -} - -// CreateSnapshot creates a new snapshot from this subscription. -// The snapshot will be for the topic this subscription is subscribed to. -// If the name is empty string, a unique name is assigned. -// -// The created snapshot is guaranteed to retain: -// (a) The existing backlog on the subscription. More precisely, this is -// defined as the messages in the subscription's backlog that are -// unacknowledged when Snapshot returns without error. -// (b) Any messages published to the subscription's topic following -// Snapshot returning without error. -func (s *Subscription) CreateSnapshot(ctx context.Context, name string) (*SnapshotConfig, error) { - if name != "" { - name = fmt.Sprintf("projects/%s/snapshots/%s", strings.Split(s.name, "/")[1], name) - } - snap, err := s.c.subc.CreateSnapshot(ctx, &pb.CreateSnapshotRequest{ - Name: name, - Subscription: s.name, - }) - if err != nil { - return nil, err - } - return toSnapshotConfig(snap, s.c) -} - -// SeekToSnapshot seeks the subscription to a snapshot. -// -// The snapshot need not be created from this subscription, -// but it must be for the topic this subscription is subscribed to. -func (s *Subscription) SeekToSnapshot(ctx context.Context, snap *Snapshot) error { - _, err := s.c.subc.Seek(ctx, &pb.SeekRequest{ - Subscription: s.name, - Target: &pb.SeekRequest_Snapshot{snap.name}, - }) - return err -} - -func toSnapshotConfig(snap *pb.Snapshot, c *Client) (*SnapshotConfig, error) { - exp, err := ptypes.Timestamp(snap.ExpireTime) - if err != nil { - return nil, err - } - return &SnapshotConfig{ - Snapshot: &Snapshot{c: c, name: snap.Name}, - Topic: newTopic(c, snap.Topic), - Expiration: exp, - }, nil -} diff --git a/vendor/cloud.google.com/go/pubsub/subscription.go b/vendor/cloud.google.com/go/pubsub/subscription.go deleted file mode 100644 index 93054d536a..0000000000 --- a/vendor/cloud.google.com/go/pubsub/subscription.go +++ /dev/null @@ -1,522 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "errors" - "fmt" - "io" - "strings" - "sync" - "time" - - "cloud.google.com/go/iam" - "cloud.google.com/go/internal/optional" - "github.com/golang/protobuf/ptypes" - durpb "github.com/golang/protobuf/ptypes/duration" - "golang.org/x/net/context" - "golang.org/x/sync/errgroup" - pb "google.golang.org/genproto/googleapis/pubsub/v1" - fmpb "google.golang.org/genproto/protobuf/field_mask" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" -) - -// Subscription is a reference to a PubSub subscription. -type Subscription struct { - c *Client - - // The fully qualified identifier for the subscription, in the format "projects//subscriptions/" - name string - - // Settings for pulling messages. Configure these before calling Receive. - ReceiveSettings ReceiveSettings - - mu sync.Mutex - receiveActive bool -} - -// Subscription creates a reference to a subscription. -func (c *Client) Subscription(id string) *Subscription { - return c.SubscriptionInProject(id, c.projectID) -} - -// SubscriptionInProject creates a reference to a subscription in a given project. -func (c *Client) SubscriptionInProject(id, projectID string) *Subscription { - return &Subscription{ - c: c, - name: fmt.Sprintf("projects/%s/subscriptions/%s", projectID, id), - } -} - -// String returns the globally unique printable name of the subscription. -func (s *Subscription) String() string { - return s.name -} - -// ID returns the unique identifier of the subscription within its project. -func (s *Subscription) ID() string { - slash := strings.LastIndex(s.name, "/") - if slash == -1 { - // name is not a fully-qualified name. - panic("bad subscription name") - } - return s.name[slash+1:] -} - -// Subscriptions returns an iterator which returns all of the subscriptions for the client's project. -func (c *Client) Subscriptions(ctx context.Context) *SubscriptionIterator { - it := c.subc.ListSubscriptions(ctx, &pb.ListSubscriptionsRequest{ - Project: c.fullyQualifiedProjectName(), - }) - return &SubscriptionIterator{ - c: c, - next: func() (string, error) { - sub, err := it.Next() - if err != nil { - return "", err - } - return sub.Name, nil - }, - } -} - -// SubscriptionIterator is an iterator that returns a series of subscriptions. -type SubscriptionIterator struct { - c *Client - next func() (string, error) -} - -// Next returns the next subscription. If there are no more subscriptions, iterator.Done will be returned. -func (subs *SubscriptionIterator) Next() (*Subscription, error) { - subName, err := subs.next() - if err != nil { - return nil, err - } - return &Subscription{c: subs.c, name: subName}, nil -} - -// PushConfig contains configuration for subscriptions that operate in push mode. -type PushConfig struct { - // A URL locating the endpoint to which messages should be pushed. - Endpoint string - - // Endpoint configuration attributes. See https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#pushconfig for more details. - Attributes map[string]string -} - -func (pc *PushConfig) toProto() *pb.PushConfig { - return &pb.PushConfig{ - Attributes: pc.Attributes, - PushEndpoint: pc.Endpoint, - } -} - -// Subscription config contains the configuration of a subscription. -type SubscriptionConfig struct { - Topic *Topic - PushConfig PushConfig - - // The default maximum time after a subscriber receives a message before - // the subscriber should acknowledge the message. Note: messages which are - // obtained via Subscription.Receive need not be acknowledged within this - // deadline, as the deadline will be automatically extended. - AckDeadline time.Duration - - // Whether to retain acknowledged messages. If true, acknowledged messages - // will not be expunged until they fall out of the RetentionDuration window. - RetainAckedMessages bool - - // How long to retain messages in backlog, from the time of publish. If - // RetainAckedMessages is true, this duration affects the retention of - // acknowledged messages, otherwise only unacknowledged messages are retained. - // Defaults to 7 days. Cannot be longer than 7 days or shorter than 10 minutes. - RetentionDuration time.Duration -} - -func (cfg *SubscriptionConfig) toProto(name string) *pb.Subscription { - var pbPushConfig *pb.PushConfig - if cfg.PushConfig.Endpoint != "" || len(cfg.PushConfig.Attributes) != 0 { - pbPushConfig = &pb.PushConfig{ - Attributes: cfg.PushConfig.Attributes, - PushEndpoint: cfg.PushConfig.Endpoint, - } - } - var retentionDuration *durpb.Duration - if cfg.RetentionDuration != 0 { - retentionDuration = ptypes.DurationProto(cfg.RetentionDuration) - } - return &pb.Subscription{ - Name: name, - Topic: cfg.Topic.name, - PushConfig: pbPushConfig, - AckDeadlineSeconds: trunc32(int64(cfg.AckDeadline.Seconds())), - RetainAckedMessages: cfg.RetainAckedMessages, - MessageRetentionDuration: retentionDuration, - } -} - -func protoToSubscriptionConfig(pbSub *pb.Subscription, c *Client) (SubscriptionConfig, error) { - rd := time.Hour * 24 * 7 - var err error - if pbSub.MessageRetentionDuration != nil { - rd, err = ptypes.Duration(pbSub.MessageRetentionDuration) - if err != nil { - return SubscriptionConfig{}, err - } - } - return SubscriptionConfig{ - Topic: newTopic(c, pbSub.Topic), - AckDeadline: time.Second * time.Duration(pbSub.AckDeadlineSeconds), - PushConfig: PushConfig{ - Endpoint: pbSub.PushConfig.PushEndpoint, - Attributes: pbSub.PushConfig.Attributes, - }, - RetainAckedMessages: pbSub.RetainAckedMessages, - RetentionDuration: rd, - }, nil -} - -// ReceiveSettings configure the Receive method. -// A zero ReceiveSettings will result in values equivalent to DefaultReceiveSettings. -type ReceiveSettings struct { - // MaxExtension is the maximum period for which the Subscription should - // automatically extend the ack deadline for each message. - // - // The Subscription will automatically extend the ack deadline of all - // fetched Messages for the duration specified. Automatic deadline - // extension may be disabled by specifying a duration less than 0. - // - // Connections may be terminated if they last longer than 30m, which - // effectively makes that the ceiling for this value. For longer message - // processing, see the example at https://godoc.org/cloud.google.com/go/pubsub/apiv1#example_SubscriberClient_Pull_lengthyClientProcessing - MaxExtension time.Duration - - // MaxOutstandingMessages is the maximum number of unprocessed messages - // (unacknowledged but not yet expired). If MaxOutstandingMessages is 0, it - // will be treated as if it were DefaultReceiveSettings.MaxOutstandingMessages. - // If the value is negative, then there will be no limit on the number of - // unprocessed messages. - MaxOutstandingMessages int - - // MaxOutstandingBytes is the maximum size of unprocessed messages - // (unacknowledged but not yet expired). If MaxOutstandingBytes is 0, it will - // be treated as if it were DefaultReceiveSettings.MaxOutstandingBytes. If - // the value is negative, then there will be no limit on the number of bytes - // for unprocessed messages. - MaxOutstandingBytes int - - // NumGoroutines is the number of goroutines Receive will spawn to pull - // messages concurrently. If NumGoroutines is less than 1, it will be treated - // as if it were DefaultReceiveSettings.NumGoroutines. - // - // NumGoroutines does not limit the number of messages that can be processed - // concurrently. Even with one goroutine, many messages might be processed at - // once, because that goroutine may continually receive messages and invoke the - // function passed to Receive on them. To limit the number of messages being - // processed concurrently, set MaxOutstandingMessages. - NumGoroutines int -} - -// DefaultReceiveSettings holds the default values for ReceiveSettings. -var DefaultReceiveSettings = ReceiveSettings{ - MaxExtension: 10 * time.Minute, - MaxOutstandingMessages: 1000, - MaxOutstandingBytes: 1e9, // 1G - NumGoroutines: 1, -} - -// Delete deletes the subscription. -func (s *Subscription) Delete(ctx context.Context) error { - return s.c.subc.DeleteSubscription(ctx, &pb.DeleteSubscriptionRequest{Subscription: s.name}) -} - -// Exists reports whether the subscription exists on the server. -func (s *Subscription) Exists(ctx context.Context) (bool, error) { - _, err := s.c.subc.GetSubscription(ctx, &pb.GetSubscriptionRequest{Subscription: s.name}) - if err == nil { - return true, nil - } - if grpc.Code(err) == codes.NotFound { - return false, nil - } - return false, err -} - -// Config fetches the current configuration for the subscription. -func (s *Subscription) Config(ctx context.Context) (SubscriptionConfig, error) { - pbSub, err := s.c.subc.GetSubscription(ctx, &pb.GetSubscriptionRequest{Subscription: s.name}) - if err != nil { - return SubscriptionConfig{}, err - } - cfg, err := protoToSubscriptionConfig(pbSub, s.c) - if err != nil { - return SubscriptionConfig{}, err - } - return cfg, nil -} - -// SubscriptionConfigToUpdate describes how to update a subscription. -type SubscriptionConfigToUpdate struct { - // If non-nil, the push config is changed. - PushConfig *PushConfig - - // If non-zero, the ack deadline is changed. - AckDeadline time.Duration - - // If set, RetainAckedMessages is changed. - RetainAckedMessages optional.Bool - - // If non-zero, RetentionDuration is changed. - RetentionDuration time.Duration -} - -// Update changes an existing subscription according to the fields set in cfg. -// It returns the new SubscriptionConfig. -// -// Update returns an error if no fields were modified. -func (s *Subscription) Update(ctx context.Context, cfg SubscriptionConfigToUpdate) (SubscriptionConfig, error) { - req := s.updateRequest(&cfg) - if len(req.UpdateMask.Paths) == 0 { - return SubscriptionConfig{}, errors.New("pubsub: UpdateSubscription call with nothing to update") - } - rpsub, err := s.c.subc.UpdateSubscription(ctx, req) - if err != nil { - return SubscriptionConfig{}, err - } - return protoToSubscriptionConfig(rpsub, s.c) -} - -func (s *Subscription) updateRequest(cfg *SubscriptionConfigToUpdate) *pb.UpdateSubscriptionRequest { - psub := &pb.Subscription{Name: s.name} - var paths []string - if cfg.PushConfig != nil { - psub.PushConfig = cfg.PushConfig.toProto() - paths = append(paths, "push_config") - } - if cfg.AckDeadline != 0 { - psub.AckDeadlineSeconds = trunc32(int64(cfg.AckDeadline.Seconds())) - paths = append(paths, "ack_deadline_seconds") - } - if cfg.RetainAckedMessages != nil { - psub.RetainAckedMessages = optional.ToBool(cfg.RetainAckedMessages) - paths = append(paths, "retain_acked_messages") - } - if cfg.RetentionDuration != 0 { - psub.MessageRetentionDuration = ptypes.DurationProto(cfg.RetentionDuration) - paths = append(paths, "message_retention_duration") - } - return &pb.UpdateSubscriptionRequest{ - Subscription: psub, - UpdateMask: &fmpb.FieldMask{Paths: paths}, - } -} - -func (s *Subscription) IAM() *iam.Handle { - return iam.InternalNewHandle(s.c.subc.Connection(), s.name) -} - -// CreateSubscription creates a new subscription on a topic. -// -// id is the name of the subscription to create. It must start with a letter, -// and contain only letters ([A-Za-z]), numbers ([0-9]), dashes (-), -// underscores (_), periods (.), tildes (~), plus (+) or percent signs (%). It -// must be between 3 and 255 characters in length, and must not start with -// "goog". -// -// cfg.Topic is the topic from which the subscription should receive messages. It -// need not belong to the same project as the subscription. This field is required. -// -// cfg.AckDeadline is the maximum time after a subscriber receives a message before -// the subscriber should acknowledge the message. It must be between 10 and 600 -// seconds (inclusive), and is rounded down to the nearest second. If the -// provided ackDeadline is 0, then the default value of 10 seconds is used. -// Note: messages which are obtained via Subscription.Receive need not be -// acknowledged within this deadline, as the deadline will be automatically -// extended. -// -// cfg.PushConfig may be set to configure this subscription for push delivery. -// -// If the subscription already exists an error will be returned. -func (c *Client) CreateSubscription(ctx context.Context, id string, cfg SubscriptionConfig) (*Subscription, error) { - if cfg.Topic == nil { - return nil, errors.New("pubsub: require non-nil Topic") - } - if cfg.AckDeadline == 0 { - cfg.AckDeadline = 10 * time.Second - } - if d := cfg.AckDeadline; d < 10*time.Second || d > 600*time.Second { - return nil, fmt.Errorf("ack deadline must be between 10 and 600 seconds; got: %v", d) - } - - sub := c.Subscription(id) - _, err := c.subc.CreateSubscription(ctx, cfg.toProto(sub.name)) - if err != nil { - return nil, err - } - return sub, nil -} - -var errReceiveInProgress = errors.New("pubsub: Receive already in progress for this subscription") - -// Receive calls f with the outstanding messages from the subscription. -// It blocks until ctx is done, or the service returns a non-retryable error. -// -// The standard way to terminate a Receive is to cancel its context: -// -// cctx, cancel := context.WithCancel(ctx) -// err := sub.Receive(cctx, callback) -// // Call cancel from callback, or another goroutine. -// -// If the service returns a non-retryable error, Receive returns that error after -// all of the outstanding calls to f have returned. If ctx is done, Receive -// returns nil after all of the outstanding calls to f have returned and -// all messages have been acknowledged or have expired. -// -// Receive calls f concurrently from multiple goroutines. It is encouraged to -// process messages synchronously in f, even if that processing is relatively -// time-consuming; Receive will spawn new goroutines for incoming messages, -// limited by MaxOutstandingMessages and MaxOutstandingBytes in ReceiveSettings. -// -// The context passed to f will be canceled when ctx is Done or there is a -// fatal service error. -// -// Receive will automatically extend the ack deadline of all fetched Messages for the -// period specified by s.ReceiveSettings.MaxExtension. -// -// Each Subscription may have only one invocation of Receive active at a time. -func (s *Subscription) Receive(ctx context.Context, f func(context.Context, *Message)) error { - s.mu.Lock() - if s.receiveActive { - s.mu.Unlock() - return errReceiveInProgress - } - s.receiveActive = true - s.mu.Unlock() - defer func() { s.mu.Lock(); s.receiveActive = false; s.mu.Unlock() }() - - config, err := s.Config(ctx) - if err != nil { - if grpc.Code(err) == codes.Canceled { - return nil - } - return err - } - maxCount := s.ReceiveSettings.MaxOutstandingMessages - if maxCount == 0 { - maxCount = DefaultReceiveSettings.MaxOutstandingMessages - } - maxBytes := s.ReceiveSettings.MaxOutstandingBytes - if maxBytes == 0 { - maxBytes = DefaultReceiveSettings.MaxOutstandingBytes - } - maxExt := s.ReceiveSettings.MaxExtension - if maxExt == 0 { - maxExt = DefaultReceiveSettings.MaxExtension - } else if maxExt < 0 { - // If MaxExtension is negative, disable automatic extension. - maxExt = 0 - } - numGoroutines := s.ReceiveSettings.NumGoroutines - if numGoroutines < 1 { - numGoroutines = DefaultReceiveSettings.NumGoroutines - } - // TODO(jba): add tests that verify that ReceiveSettings are correctly processed. - po := &pullOptions{ - maxExtension: maxExt, - maxPrefetch: trunc32(int64(maxCount)), - ackDeadline: config.AckDeadline, - } - fc := newFlowController(maxCount, maxBytes) - - // Wait for all goroutines started by Receive to return, so instead of an - // obscure goroutine leak we have an obvious blocked call to Receive. - group, gctx := errgroup.WithContext(ctx) - for i := 0; i < numGoroutines; i++ { - group.Go(func() error { - return s.receive(gctx, po, fc, f) - }) - } - return group.Wait() -} - -func (s *Subscription) receive(ctx context.Context, po *pullOptions, fc *flowController, f func(context.Context, *Message)) error { - // Cancel a sub-context when we return, to kick the context-aware callbacks - // and the goroutine below. - ctx2, cancel := context.WithCancel(ctx) - // Call stop when Receive's context is done. - // Stop will block until all outstanding messages have been acknowledged - // or there was a fatal service error. - // The iterator does not use the context passed to Receive. If it did, canceling - // that context would immediately stop the iterator without waiting for unacked - // messages. - iter := newMessageIterator(context.Background(), s.c.subc, s.name, po) - - // We cannot use errgroup from Receive here. Receive might already be calling group.Wait, - // and group.Wait cannot be called concurrently with group.Go. We give each receive() its - // own WaitGroup instead. - // Since wg.Add is only called from the main goroutine, wg.Wait is guaranteed - // to be called after all Adds. - var wg sync.WaitGroup - wg.Add(1) - go func() { - <-ctx2.Done() - iter.stop() - wg.Done() - }() - defer wg.Wait() - - defer cancel() - for { - msgs, err := iter.receive() - if err == io.EOF { - return nil - } - if err != nil { - return err - } - for i, msg := range msgs { - msg := msg - // TODO(jba): call acquire closer to when the message is allocated. - if err := fc.acquire(ctx, len(msg.Data)); err != nil { - // TODO(jba): test that these "orphaned" messages are nacked immediately when ctx is done. - for _, m := range msgs[i:] { - m.Nack() - } - return nil - } - old := msg.doneFunc - msgLen := len(msg.Data) - msg.doneFunc = func(ackID string, ack bool, receiveTime time.Time) { - defer fc.release(msgLen) - old(ackID, ack, receiveTime) - } - wg.Add(1) - go func() { - defer wg.Done() - f(ctx2, msg) - }() - } - } -} - -// TODO(jba): remove when we delete messageIterator. -type pullOptions struct { - maxExtension time.Duration - maxPrefetch int32 - // ackDeadline is the default ack deadline for the subscription. Not - // configurable. - ackDeadline time.Duration -} diff --git a/vendor/cloud.google.com/go/pubsub/topic.go b/vendor/cloud.google.com/go/pubsub/topic.go deleted file mode 100644 index 388d4510e6..0000000000 --- a/vendor/cloud.google.com/go/pubsub/topic.go +++ /dev/null @@ -1,397 +0,0 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// 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 pubsub - -import ( - "errors" - "fmt" - "runtime" - "strings" - "sync" - "time" - - "cloud.google.com/go/iam" - "github.com/golang/protobuf/proto" - gax "github.com/googleapis/gax-go" - "golang.org/x/net/context" - "google.golang.org/api/support/bundler" - pb "google.golang.org/genproto/googleapis/pubsub/v1" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" -) - -const ( - // The maximum number of messages that can be in a single publish request, as - // determined by the PubSub service. - MaxPublishRequestCount = 1000 - - // The maximum size of a single publish request in bytes, as determined by the PubSub service. - MaxPublishRequestBytes = 1e7 - - maxInt = int(^uint(0) >> 1) -) - -// ErrOversizedMessage indicates that a message's size exceeds MaxPublishRequestBytes. -var ErrOversizedMessage = bundler.ErrOversizedItem - -// Topic is a reference to a PubSub topic. -// -// The methods of Topic are safe for use by multiple goroutines. -type Topic struct { - c *Client - // The fully qualified identifier for the topic, in the format "projects//topics/" - name string - - // Settings for publishing messages. All changes must be made before the - // first call to Publish. The default is DefaultPublishSettings. - PublishSettings PublishSettings - - mu sync.RWMutex - stopped bool - bundler *bundler.Bundler - - wg sync.WaitGroup - - // Channel for message bundles to be published. Close to indicate that Stop was called. - bundlec chan []*bundledMessage -} - -// PublishSettings control the bundling of published messages. -type PublishSettings struct { - - // Publish a non-empty batch after this delay has passed. - DelayThreshold time.Duration - - // Publish a batch when it has this many messages. The maximum is - // MaxPublishRequestCount. - CountThreshold int - - // Publish a batch when its size in bytes reaches this value. - ByteThreshold int - - // The number of goroutines that invoke the Publish RPC concurrently. - // Defaults to a multiple of GOMAXPROCS. - NumGoroutines int - - // The maximum time that the client will attempt to publish a bundle of messages. - Timeout time.Duration -} - -// DefaultPublishSettings holds the default values for topics' PublishSettings. -var DefaultPublishSettings = PublishSettings{ - DelayThreshold: 1 * time.Millisecond, - CountThreshold: 100, - ByteThreshold: 1e6, - Timeout: 60 * time.Second, -} - -// CreateTopic creates a new topic. -// The specified topic ID must start with a letter, and contain only letters -// ([A-Za-z]), numbers ([0-9]), dashes (-), underscores (_), periods (.), -// tildes (~), plus (+) or percent signs (%). It must be between 3 and 255 -// characters in length, and must not start with "goog". -// If the topic already exists an error will be returned. -func (c *Client) CreateTopic(ctx context.Context, id string) (*Topic, error) { - t := c.Topic(id) - _, err := c.pubc.CreateTopic(ctx, &pb.Topic{Name: t.name}) - if err != nil { - return nil, err - } - return t, nil -} - -// Topic creates a reference to a topic in the client's project. -// -// If a Topic's Publish method is called, it has background goroutines -// associated with it. Clean them up by calling Topic.Stop. -// -// Avoid creating many Topic instances if you use them to publish. -func (c *Client) Topic(id string) *Topic { - return c.TopicInProject(id, c.projectID) -} - -// TopicInProject creates a reference to a topic in the given project. -// -// If a Topic's Publish method is called, it has background goroutines -// associated with it. Clean them up by calling Topic.Stop. -// -// Avoid creating many Topic instances if you use them to publish. -func (c *Client) TopicInProject(id, projectID string) *Topic { - return newTopic(c, fmt.Sprintf("projects/%s/topics/%s", projectID, id)) -} - -func newTopic(c *Client, name string) *Topic { - // bundlec is unbuffered. A buffer would occupy memory not - // accounted for by the bundler, so BufferedByteLimit would be a lie: - // the actual memory consumed would be higher. - return &Topic{ - c: c, - name: name, - PublishSettings: DefaultPublishSettings, - bundlec: make(chan []*bundledMessage), - } -} - -// Topics returns an iterator which returns all of the topics for the client's project. -func (c *Client) Topics(ctx context.Context) *TopicIterator { - it := c.pubc.ListTopics(ctx, &pb.ListTopicsRequest{Project: c.fullyQualifiedProjectName()}) - return &TopicIterator{ - c: c, - next: func() (string, error) { - topic, err := it.Next() - if err != nil { - return "", err - } - return topic.Name, nil - }, - } -} - -// TopicIterator is an iterator that returns a series of topics. -type TopicIterator struct { - c *Client - next func() (string, error) -} - -// Next returns the next topic. If there are no more topics, iterator.Done will be returned. -func (tps *TopicIterator) Next() (*Topic, error) { - topicName, err := tps.next() - if err != nil { - return nil, err - } - return newTopic(tps.c, topicName), nil -} - -// ID returns the unique idenfier of the topic within its project. -func (t *Topic) ID() string { - slash := strings.LastIndex(t.name, "/") - if slash == -1 { - // name is not a fully-qualified name. - panic("bad topic name") - } - return t.name[slash+1:] -} - -// String returns the printable globally unique name for the topic. -func (t *Topic) String() string { - return t.name -} - -// Delete deletes the topic. -func (t *Topic) Delete(ctx context.Context) error { - return t.c.pubc.DeleteTopic(ctx, &pb.DeleteTopicRequest{Topic: t.name}) -} - -// Exists reports whether the topic exists on the server. -func (t *Topic) Exists(ctx context.Context) (bool, error) { - if t.name == "_deleted-topic_" { - return false, nil - } - _, err := t.c.pubc.GetTopic(ctx, &pb.GetTopicRequest{Topic: t.name}) - if err == nil { - return true, nil - } - if grpc.Code(err) == codes.NotFound { - return false, nil - } - return false, err -} - -func (t *Topic) IAM() *iam.Handle { - return iam.InternalNewHandle(t.c.pubc.Connection(), t.name) -} - -// Subscriptions returns an iterator which returns the subscriptions for this topic. -// -// Some of the returned subscriptions may belong to a project other than t. -func (t *Topic) Subscriptions(ctx context.Context) *SubscriptionIterator { - it := t.c.pubc.ListTopicSubscriptions(ctx, &pb.ListTopicSubscriptionsRequest{ - Topic: t.name, - }) - return &SubscriptionIterator{ - c: t.c, - next: it.Next, - } -} - -var errTopicStopped = errors.New("pubsub: Stop has been called for this topic") - -// Publish publishes msg to the topic asynchronously. Messages are batched and -// sent according to the topic's PublishSettings. Publish never blocks. -// -// Publish returns a non-nil PublishResult which will be ready when the -// message has been sent (or has failed to be sent) to the server. -// -// Publish creates goroutines for batching and sending messages. These goroutines -// need to be stopped by calling t.Stop(). Once stopped, future calls to Publish -// will immediately return a PublishResult with an error. -func (t *Topic) Publish(ctx context.Context, msg *Message) *PublishResult { - // TODO(jba): if this turns out to take significant time, try to approximate it. - // Or, convert the messages to protos in Publish, instead of in the service. - msg.size = proto.Size(&pb.PubsubMessage{ - Data: msg.Data, - Attributes: msg.Attributes, - }) - r := &PublishResult{ready: make(chan struct{})} - t.initBundler() - t.mu.RLock() - defer t.mu.RUnlock() - // TODO(aboulhosn) [from bcmills] consider changing the semantics of bundler to perform this logic so we don't have to do it here - if t.stopped { - r.set("", errTopicStopped) - return r - } - - // TODO(jba) [from bcmills] consider using a shared channel per bundle - // (requires Bundler API changes; would reduce allocations) - // The call to Add should never return an error because the bundler's - // BufferedByteLimit is set to maxInt; we do not perform any flow - // control in the client. - err := t.bundler.Add(&bundledMessage{msg, r}, msg.size) - if err != nil { - r.set("", err) - } - return r -} - -// Send all remaining published messages and stop goroutines created for handling -// publishing. Returns once all outstanding messages have been sent or have -// failed to be sent. -func (t *Topic) Stop() { - t.mu.Lock() - noop := t.stopped || t.bundler == nil - t.stopped = true - t.mu.Unlock() - if noop { - return - } - t.bundler.Flush() - // At this point, all pending bundles have been published and the bundler's - // goroutines have exited, so it is OK for this goroutine to close bundlec. - close(t.bundlec) - t.wg.Wait() -} - -// A PublishResult holds the result from a call to Publish. -type PublishResult struct { - ready chan struct{} - serverID string - err error -} - -// Ready returns a channel that is closed when the result is ready. -// When the Ready channel is closed, Get is guaranteed not to block. -func (r *PublishResult) Ready() <-chan struct{} { return r.ready } - -// Get returns the server-generated message ID and/or error result of a Publish call. -// Get blocks until the Publish call completes or the context is done. -func (r *PublishResult) Get(ctx context.Context) (serverID string, err error) { - // If the result is already ready, return it even if the context is done. - select { - case <-r.Ready(): - return r.serverID, r.err - default: - } - select { - case <-ctx.Done(): - return "", ctx.Err() - case <-r.Ready(): - return r.serverID, r.err - } -} - -func (r *PublishResult) set(sid string, err error) { - r.serverID = sid - r.err = err - close(r.ready) -} - -type bundledMessage struct { - msg *Message - res *PublishResult -} - -func (t *Topic) initBundler() { - t.mu.RLock() - noop := t.stopped || t.bundler != nil - t.mu.RUnlock() - if noop { - return - } - t.mu.Lock() - defer t.mu.Unlock() - // Must re-check, since we released the lock. - if t.stopped || t.bundler != nil { - return - } - - // TODO(jba): use a context detached from the one passed to NewClient. - ctx := context.TODO() - // Unless overridden, run several goroutines per CPU to call the Publish RPC. - n := t.PublishSettings.NumGoroutines - if n <= 0 { - n = 25 * runtime.GOMAXPROCS(0) - } - timeout := t.PublishSettings.Timeout - t.wg.Add(n) - for i := 0; i < n; i++ { - go func() { - defer t.wg.Done() - for b := range t.bundlec { - bctx := ctx - cancel := func() {} - if timeout != 0 { - bctx, cancel = context.WithTimeout(ctx, timeout) - } - t.publishMessageBundle(bctx, b) - cancel() - } - }() - } - t.bundler = bundler.NewBundler(&bundledMessage{}, func(items interface{}) { - t.bundlec <- items.([]*bundledMessage) - - }) - t.bundler.DelayThreshold = t.PublishSettings.DelayThreshold - t.bundler.BundleCountThreshold = t.PublishSettings.CountThreshold - if t.bundler.BundleCountThreshold > MaxPublishRequestCount { - t.bundler.BundleCountThreshold = MaxPublishRequestCount - } - t.bundler.BundleByteThreshold = t.PublishSettings.ByteThreshold - t.bundler.BufferedByteLimit = maxInt - t.bundler.BundleByteLimit = MaxPublishRequestBytes -} - -func (t *Topic) publishMessageBundle(ctx context.Context, bms []*bundledMessage) { - pbMsgs := make([]*pb.PubsubMessage, len(bms)) - for i, bm := range bms { - pbMsgs[i] = &pb.PubsubMessage{ - Data: bm.msg.Data, - Attributes: bm.msg.Attributes, - } - bm.msg = nil // release bm.msg for GC - } - res, err := t.c.pubc.Publish(ctx, &pb.PublishRequest{ - Topic: t.name, - Messages: pbMsgs, - }, gax.WithGRPCOptions(grpc.MaxCallSendMsgSize(maxSendRecvBytes))) - for i, bm := range bms { - if err != nil { - bm.res.set("", err) - } else { - bm.res.set(res.MessageIds[i], nil) - } - } -}