Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Removing unused pubsubSecret from sources.spec (#567)
Browse files Browse the repository at this point in the history
* adding github template for bugs and features

* renaming

* adding comment

* nits

* nits

* updating to master

* missing files

* using revision instead of master

* removing pubsubsecret. Other validation cleanup.
  • Loading branch information
nachocano authored Feb 26, 2020
1 parent 86afc8f commit 83f9e1c
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 457 deletions.
5 changes: 1 addition & 4 deletions config/300-cloudauditlogssource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ spec:
properties:
secret:
type: object
description: "Credential used to pull Stackdriver audit log pubsub messages. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys). If omitted, defaults to 'google-cloud-key'"
pubSubSecret:
type: object
description: "Optional credential to use for creating a Topic and subscribing to the Topic. If omitted, uses secret. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys)."
description: "Credential used to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
serviceAccountName:
type: string
description: "Service Account to run Receive Adapter as. If omitted, uses 'default'."
Expand Down
2 changes: 1 addition & 1 deletion config/300-cloudpubsubsource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ spec:
properties:
secret:
type: object
description: "Credential to use to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
description: "Credential used to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
project:
type: string
description: "ID of the Google Cloud Project that the Pub/Sub Topic exists in. E.g. 'my-project-1234' rather than its display name, 'My Project' or its number '1234567890'. If omitted uses the Project ID from the GKE cluster metadata service."
Expand Down
5 changes: 1 addition & 4 deletions config/300-cloudschedulersource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ spec:
properties:
secret:
type: object
description: "Credential to use for managing Scheduler Jobs. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys). If omitted, defaults to 'google-cloud-key'."
pubSubSecret:
type: object
description: "Optional credential to use for creating a Topic and subscribing to the Topic. If omitted, uses secret. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys)."
description: "Credential used to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
project:
type: string
description: "Google Cloud Project ID of the project into which the Scheduler job should be created. If omitted uses the Project ID from the GKE cluster metadata service."
Expand Down
5 changes: 1 addition & 4 deletions config/300-cloudstoragesource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ spec:
properties:
secret:
type: object
description: "Credential to use for managing GCS notifications. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys). If omitted, defaults to 'google-cloud-key'."
pubSubSecret:
type: object
description: "Optional credential to use for creating a Topic and subscribing to the Topic. If omitted, uses secret. Must be a service account key in JSON format (see https://cloud.google.com/iam/docs/creating-managing-service-account-keys)."
description: "Credential used to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
serviceAccountName:
type: string
description: "Service Account to run Receive Adapter as. If omitted, uses 'default'."
Expand Down
2 changes: 1 addition & 1 deletion config/300-pullsubscription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spec:
properties:
secret:
type: object
description: "Credential to use to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
description: "Credential used to poll the Cloud Pub/Sub 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). Defaults to secret.name of 'google-cloud-key' and secret.key of 'key.json'."
project:
type: string
description: "ID of the Google Cloud Project that the Pub/Sub Topic exists in. E.g. 'my-project-1234' rather than its display name, 'My Project' or its number '1234567890'. If omitted uses the Project ID from the GKE cluster metadata service."
Expand Down
10 changes: 1 addition & 9 deletions pkg/apis/duck/v1alpha1/pubsub_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ type PubSubSpec struct {
// This brings in CloudEventOverrides and Sink.
duckv1.SourceSpec `json:",inline"`

// Secret is the credential to use to create the "entity" in GCP.
// Secret is the credential to use to poll from a Cloud Pub/Sub subscription.
// If not specified, defaults to:
// Name: google-cloud-key
// Key: key.json
// +optional
Secret *corev1.SecretKeySelector `json:"secret,omitempty"`

// PubSubSecret is the credential to use to create
// Topic / PullSubscription resources. If omitted, uses Secret
PubSubSecret *corev1.SecretKeySelector `json:"pubsubSecret,omitempty"`

// Project is the ID of the Google Cloud Project that the PubSub Topic exists in.
// If omitted, defaults to same as the cluster.
// +optional
Expand Down Expand Up @@ -134,10 +130,6 @@ func (s *PubSub) Populate() {
LocalObjectReference: corev1.LocalObjectReference{Name: "secret"},
Key: "secretkey",
}
s.Spec.PubSubSecret = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "pubsubsecret"},
Key: "pubsubkey",
}
s.Status.ObservedGeneration = 42
s.Status.Conditions = duckv1.Conditions{{
// Populate ALL fields
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/duck/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/apis/events/v1alpha1/cloudauditlogssource_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ package v1alpha1

import (
"context"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

func (current *CloudAuditLogsSource) Validate(ctx context.Context) *apis.FieldError {
Expand All @@ -29,6 +33,14 @@ func (current *CloudAuditLogsSource) Validate(ctx context.Context) *apis.FieldEr

func (current *CloudAuditLogsSourceSpec) Validate(ctx context.Context) *apis.FieldError {
var errs *apis.FieldError

// Sink [required]
if equality.Semantic.DeepEqual(current.Sink, duckv1.Destination{}) {
errs = errs.Also(apis.ErrMissingField("sink"))
} else if err := current.Sink.Validate(ctx); err != nil {
errs = errs.Also(err.ViaField("sink"))
}

// ServiceName [required]
if current.ServiceName == "" {
errs = errs.Also(apis.ErrMissingField("serviceName"))
Expand All @@ -38,6 +50,15 @@ func (current *CloudAuditLogsSourceSpec) Validate(ctx context.Context) *apis.Fie
errs = errs.Also(apis.ErrMissingField("methodName"))
}

if current.Secret != nil {
if !equality.Semantic.DeepEqual(current.Secret, &corev1.SecretKeySelector{}) {
err := validateSecret(current.Secret)
if err != nil {
errs = errs.Also(err.ViaField("secret"))
}
}
}

return errs
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/events/v1alpha1/cloudauditlogssource_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func TestCloudAuditLogsSourceValidationFields(t *testing.T) {
}(),
error: true,
},
"invalid scheduler secret, missing key": {
spec: func() CloudAuditLogsSourceSpec {
obj := auditLogsSourceSpec.DeepCopy()
obj.Secret = &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "test-secret"},
}
return *obj
}(),
error: true,
},
}
for n, tc := range testCases {
t.Run(n, func(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/apis/events/v1alpha1/cloudpubsubsource_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

duckv1alpha1 "github.com/google/knative-gcp/pkg/apis/duck/v1alpha1"
corev1 "k8s.io/api/core/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -76,6 +77,15 @@ func (current *CloudPubSubSourceSpec) Validate(ctx context.Context) *apis.FieldE
}
}

if current.Secret != nil {
if !equality.Semantic.DeepEqual(current.Secret, &corev1.SecretKeySelector{}) {
err := validateSecret(current.Secret)
if err != nil {
errs = errs.Also(err.ViaField("secret"))
}
}
}

return errs
}

Expand Down
Loading

0 comments on commit 83f9e1c

Please sign in to comment.