|
| 1 | +/* |
| 2 | +Copyright 2020 The Knative Authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | + "k8s.io/apimachinery/pkg/runtime" |
| 22 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 23 | + "knative.dev/pkg/apis" |
| 24 | + duckv1 "knative.dev/pkg/apis/duck/v1" |
| 25 | + "knative.dev/pkg/kmeta" |
| 26 | +) |
| 27 | + |
| 28 | +// +genclient |
| 29 | +// +genreconciler |
| 30 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 31 | + |
| 32 | +// IntegrationSource is the Schema for the Integrationsources API |
| 33 | +type IntegrationSource struct { |
| 34 | + metav1.TypeMeta `json:",inline"` |
| 35 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 36 | + |
| 37 | + Spec IntegrationSourceSpec `json:"spec,omitempty"` |
| 38 | + Status IntegrationSourceStatus `json:"status,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +var ( |
| 42 | + _ runtime.Object = (*IntegrationSource)(nil) |
| 43 | + _ kmeta.OwnerRefable = (*IntegrationSource)(nil) |
| 44 | + _ apis.Validatable = (*IntegrationSource)(nil) |
| 45 | + _ apis.Defaultable = (*IntegrationSource)(nil) |
| 46 | + _ apis.HasSpec = (*IntegrationSource)(nil) |
| 47 | + _ duckv1.KRShaped = (*IntegrationSource)(nil) |
| 48 | + _ apis.Convertible = (*IntegrationSource)(nil) |
| 49 | +) |
| 50 | + |
| 51 | +// IntegrationSourceSpec defines the desired state of IntegrationSource |
| 52 | +type IntegrationSourceSpec struct { |
| 53 | + // inherits duck/v1 SourceSpec, which currently provides: |
| 54 | + // * Sink - a reference to an object that will resolve to a domain name or |
| 55 | + // a URI directly to use as the sink. |
| 56 | + // * CloudEventOverrides - defines overrides to control the output format |
| 57 | + // and modifications of the event sent to the sink. |
| 58 | + duckv1.SourceSpec `json:",inline"` |
| 59 | + |
| 60 | + Aws *Aws `json:"aws,omitempty"` // AWS source configuration |
| 61 | + Timer *Timer `json:"timer,omitempty"` // Timer configuration |
| 62 | +} |
| 63 | + |
| 64 | +type Timer struct { |
| 65 | + Period int `json:"period" default:"1000"` // Interval (in milliseconds) between producing messages |
| 66 | + Message string `json:"message"` // Message to generate |
| 67 | + ContentType string `json:"contentType" default:"text/plain"` // Content type of generated message |
| 68 | + RepeatCount int `json:"repeatCount,omitempty"` // Max number of fires (optional) |
| 69 | +} |
| 70 | + |
| 71 | +type AWSCommon struct { |
| 72 | + // Auth is the S3 authentication (accessKey/secretKey) configuration. |
| 73 | + Region string `json:"region,omitempty"` // AWS region |
| 74 | + ProfileCredentialsName string `json:"profileCredentialsName,omitempty"` // Profile name for profile credentials provider |
| 75 | + SessionToken string `json:"sessionToken,omitempty"` // Session token |
| 76 | + URIEndpointOverride string `json:"uriEndpointOverride,omitempty"` // Override endpoint URI |
| 77 | + OverrideEndpoint bool `json:"overrideEndpoint" default:"false"` // Override endpoint flag |
| 78 | +} |
| 79 | + |
| 80 | +type AWSS3 struct { |
| 81 | + AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON |
| 82 | + BucketNameOrArn string `json:"bucketNameOrArn,omitempty"` // S3 Bucket name or ARN |
| 83 | + DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete objects after reading |
| 84 | + MoveAfterRead bool `json:"moveAfterRead" default:"false"` // Move objects after reading |
| 85 | + DestinationBucket string `json:"destinationBucket,omitempty"` // Destination bucket for moved objects |
| 86 | + DestinationBucketPrefix string `json:"destinationBucketPrefix,omitempty"` // Prefix for moved objects |
| 87 | + DestinationBucketSuffix string `json:"destinationBucketSuffix,omitempty"` // Suffix for moved objects |
| 88 | + AutoCreateBucket bool `json:"autoCreateBucket" default:"false"` // Auto-create S3 bucket |
| 89 | + Prefix string `json:"prefix,omitempty"` // S3 bucket prefix for search |
| 90 | + IgnoreBody bool `json:"ignoreBody" default:"false"` // Ignore object body |
| 91 | + ForcePathStyle bool `json:"forcePathStyle" default:"false"` // Force path style for bucket access |
| 92 | + Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds |
| 93 | + MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"10"` // Max messages to poll per request |
| 94 | +} |
| 95 | + |
| 96 | +type AWSSQS struct { |
| 97 | + AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON |
| 98 | + QueueNameOrArn string `json:"queueNameOrArn,omitempty"` // SQS Queue name or ARN |
| 99 | + DeleteAfterRead bool `json:"deleteAfterRead" default:"true"` // Auto-delete messages after reading |
| 100 | + AutoCreateQueue bool `json:"autoCreateQueue" default:"false"` // Auto-create SQS queue |
| 101 | + AmazonAWSHost string `json:"amazonAWSHost" default:"amazonaws.com"` // AWS host |
| 102 | + Protocol string `json:"protocol" default:"https"` // Communication protocol (http/https) |
| 103 | + QueueURL string `json:"queueURL,omitempty"` // Full SQS queue URL |
| 104 | + Greedy bool `json:"greedy" default:"false"` // Greedy scheduler |
| 105 | + Delay int `json:"delay" default:"500"` // Delay between polls in milliseconds |
| 106 | + MaxMessagesPerPoll int `json:"maxMessagesPerPoll" default:"1"` // Max messages to return (1-10) |
| 107 | + WaitTimeSeconds int `json:"waitTimeSeconds,omitempty"` // Wait time for messages |
| 108 | + VisibilityTimeout int `json:"visibilityTimeout,omitempty"` // Visibility timeout in seconds |
| 109 | +} |
| 110 | + |
| 111 | +type AWSDDBStreams struct { |
| 112 | + AWSCommon `json:",inline"` // Embeds AWSCommon to inherit its fields in JSON |
| 113 | + Table string `json:"table,omitempty"` // The name of the DynamoDB table |
| 114 | + StreamIteratorType string `json:"streamIteratorType,omitempty" default:"FROM_LATEST"` // Defines where in the DynamoDB stream to start getting records |
| 115 | + Delay int `json:"delay,omitempty" default:"500"` // Delay in milliseconds before the next poll from the database |
| 116 | +} |
| 117 | + |
| 118 | +type Aws struct { |
| 119 | + S3 *AWSS3 `json:"s3,omitempty"` // S3 source configuration |
| 120 | + SQS *AWSSQS `json:"sqs,omitempty"` // SQS source configuration |
| 121 | + DDBStreams *AWSDDBStreams `json:"ddb-streams,omitempty"` // DynamoDB Streams source configuration |
| 122 | + Auth *Auth `json:"auth,omitempty"` |
| 123 | +} |
| 124 | + |
| 125 | +type Auth struct { |
| 126 | + // Auth Secret |
| 127 | + Secret *Secret `json:"secret,omitempty"` |
| 128 | + |
| 129 | + // AccessKey is the AWS access key ID. |
| 130 | + AccessKey string `json:"accessKey,omitempty"` |
| 131 | + |
| 132 | + // SecretKey is the AWS secret access key. |
| 133 | + SecretKey string `json:"secretKey,omitempty"` |
| 134 | +} |
| 135 | + |
| 136 | +func (a *Auth) HasAuth() bool { |
| 137 | + return a != nil && a.Secret != nil && |
| 138 | + a.Secret.Ref != nil && a.Secret.Ref.Name != "" |
| 139 | +} |
| 140 | + |
| 141 | +type Secret struct { |
| 142 | + // Secret reference for SASL and SSL configurations. |
| 143 | + Ref *SecretReference `json:"ref,omitempty"` |
| 144 | +} |
| 145 | + |
| 146 | +type SecretReference struct { |
| 147 | + // Secret name. |
| 148 | + Name string `json:"name"` |
| 149 | +} |
| 150 | + |
| 151 | +// GetGroupVersionKind returns the GroupVersionKind. |
| 152 | +func (*IntegrationSource) GetGroupVersionKind() schema.GroupVersionKind { |
| 153 | + return SchemeGroupVersion.WithKind("IntegrationSource") |
| 154 | +} |
| 155 | + |
| 156 | +// IntegrationSourceStatus defines the observed state of IntegrationSource |
| 157 | +type IntegrationSourceStatus struct { |
| 158 | + // inherits duck/v1 SourceStatus, which currently provides: |
| 159 | + // * ObservedGeneration - the 'Generation' of the Service that was last |
| 160 | + // processed by the controller. |
| 161 | + // * Conditions - the latest available observations of a resource's current |
| 162 | + // state. |
| 163 | + // * SinkURI - the current active sink URI that has been configured for the |
| 164 | + // Source. |
| 165 | + duckv1.SourceStatus `json:",inline"` |
| 166 | +} |
| 167 | + |
| 168 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 169 | + |
| 170 | +// IntegrationSourceList contains a list of IntegrationSource |
| 171 | +type IntegrationSourceList struct { |
| 172 | + metav1.TypeMeta `json:",inline"` |
| 173 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 174 | + Items []IntegrationSource `json:"items"` |
| 175 | +} |
| 176 | + |
| 177 | +// GetUntypedSpec returns the spec of the IntegrationSource. |
| 178 | +func (c *IntegrationSource) GetUntypedSpec() interface{} { |
| 179 | + return c.Spec |
| 180 | +} |
| 181 | + |
| 182 | +// GetStatus retrieves the status of the IntegrationSource. Implements the KRShaped interface. |
| 183 | +func (c *IntegrationSource) GetStatus() *duckv1.Status { |
| 184 | + return &c.Status.Status |
| 185 | +} |
0 commit comments