@@ -59,6 +59,13 @@ func (current *CloudAuditLogsSourceSpec) Validate(ctx context.Context) *apis.Fie
 		}
 	}
 
+	if current.ServiceAccount != nil {
+		err := validateGCPServiceAccount(current.ServiceAccount)
+		if err != nil {
+			errs = errs.Also(err.ViaField("serviceAccount"))
+		}
+	}
+
 	return errs
 }
 
/*
Copyright 2020 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

    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"
	"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 {
	return current.Spec.Validate(ctx).ViaField("spec")
}

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"))
	}
	// MethodName [required]
	if current.MethodName == "" {
		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
}

func (current *CloudAuditLogsSource) CheckImmutableFields(ctx context.Context, original *CloudAuditLogsSource) *apis.FieldError {
	if original == nil {
		return nil
	}

	// Modification of Topic, Secret, Project, ServiceName, MethodName, and ResourceName are not allowed. Everything else is mutable.
	if diff := cmp.Diff(original.Spec, current.Spec,
		cmpopts.IgnoreFields(CloudAuditLogsSourceSpec{},
			"Sink", "CloudEventOverrides")); diff != "" {
		return &apis.FieldError{
			Message: "Immutable fields changed (-old +new)",
			Paths:   []string{"spec"},
			Details: diff,
		}
	}
	return nil
}

just check for != "", when you change the pointer to just a string