Skip to content

Commit

Permalink
Add ServiceAttachment v1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
swetharepakula committed Nov 8, 2021
1 parent 6af12c2 commit fd41fb1
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ echo "Performing code generation for ServiceAttachment CRD"
${CODEGEN_PKG}/generate-groups.sh \
"deepcopy,client,informer,lister" \
k8s.io/ingress-gce/pkg/serviceattachment/client k8s.io/ingress-gce/pkg/apis \
"serviceattachment:v1beta1" \
"serviceattachment:v1beta1,v1" \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Generating openapi for ServiceAttachment v1beta1"
Expand All @@ -95,6 +95,14 @@ ${GOPATH}/bin/openapi-gen \
--output-package k8s.io/ingress-gce/pkg/apis/serviceattachment/v1beta1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Generating openapi for ServiceAttachment v1"
go install ${OPENAPI_PKG}/cmd/openapi-gen
${GOPATH}/bin/openapi-gen \
--output-file-base zz_generated.openapi \
--input-dirs k8s.io/ingress-gce/pkg/apis/serviceattachment/v1\
--output-package k8s.io/ingress-gce/pkg/apis/serviceattachment/v1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Performing code generation for GCPIngressParams CRD"
${CODEGEN_PKG}/generate-groups.sh \
"deepcopy,informer,lister" \
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/serviceattachment/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 The Kubernetes 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.
*/

// +k8s:deepcopy-gen=package

// Package v1 is the v1 version of the API.
// +groupName=networking.gke.io
package v1
52 changes: 52 additions & 0 deletions pkg/apis/serviceattachment/v1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2020 The Kubernetes 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 v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/ingress-gce/pkg/apis/serviceattachment"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: serviceattachment.GroupName, Version: "v1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme
)

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ServiceAttachment{},
&ServiceAttachmentList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
143 changes: 143 additions & 0 deletions pkg/apis/serviceattachment/v1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
Copyright 2020 The Kubernetes 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 v1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ServiceAttachment represents a Service Attachment associated with a service/ingress/gateway class
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
type ServiceAttachment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ServiceAttachmentSpec `json:"spec,omitempty"`
Status ServiceAttachmentStatus `json:"status,omitempty"`
}

// ServiceAttachmentSpec is the spec for a ServiceAttachment resource
// +k8s:openapi-gen=true
type ServiceAttachmentSpec struct {
// ConnectionPreference determines how consumers are accepted.
// +required
ConnectionPreference string `json:"connectionPreference,omitempty"`

// NATSubnets contains the list of subnet names for PSC
// +required
// +listType=atomic
NATSubnets []string `json:"natSubnets,omitempty"`

// ResourceRef is the reference to the K8s resource that created the forwarding rule
// Only Services can be used as a reference
// +required
ResourceRef corev1.TypedLocalObjectReference `json:"resourceRef,omitempty"`

// ProxyProtocol when set will expose client information TCP/IP information
// +optional
ProxyProtocol bool `json:"proxyProtocol,omitempty"`

// ConsumerAllowList is list of consumer projects that should be allow listed
// for this ServiceAttachment
// +optional
// +listType=atomic
ConsumerAllowList []ConsumerProject `json:"consumerAllowList,omitempty"`

// ConsumerRejectList is the list of Consumer Project IDs or Numbers that should
// be rejected for this ServiceAttachment
// +optional
// +listType=atomic
ConsumerRejectList []string `json:"consumerRejectList,omitempty"`
}

// ConsumerProject is the consumer project and project level configuration
// +k8s:openapi-gen=true
type ConsumerProject struct {
// ConnectionLimit is the connection limit for this Consumer project
// +optional
ConnectionLimit int64 `json:"connectionLimit,omitempty"`

// Project is the project id or number for the project to set the
// limit for.
// +required
Project string `json:"project,omitempty"`

// ForceSendFields is a list of field names (e.g. "ConnectionLimit") to
// unconditionally include in API requests. By default, fields with
// empty values are omitted from API requests. However, any non-pointer,
// non-interface field appearing in ForceSendFields will be sent to the
// server regardless of whether the field is empty or not. This may be
// used to include empty fields in Patch requests.
// +optional
// +listType=atomic
ForceSendFields []string `json:"forceSendFields,omitempty"`

// NullFields is a list of field names (e.g. "ConnectionLimit") to
// include in API requests with the JSON null value. By default, fields
// with empty values are omitted from API requests. However, any field
// with an empty value appearing in NullFields will be sent to the
// server as null. It is an error if a field in this list has a
// non-empty value. This may be used to include null fields in Patch
// requests.
// +optional
// +listType=atomic
NullFields []string `json:"nullFields,omitempty"`
}

// ServiceAttachmentStatus is the status for a ServiceAttachment resource
// +k8s:openapi-gen=true
type ServiceAttachmentStatus struct {
// ServiceAttachmentURL is the URL for the GCE Service Attachment resource
// +optional
ServiceAttachmentURL string `json:"serviceAttachmentURL,omitempty"`

// ForwardingRuleURL is the URL to the GCE Forwarding Rule resource the
// Service Attachment points to
// +optional
ForwardingRuleURL string `json:"forwardingRuleURL,omitempty"`

// Consumer Forwarding Rules using ts Service Attachment
// +listType=atomic
// +optional
ConsumerForwardingRules []ConsumerForwardingRule `json:"consumerForwardingRules,omitempty"`

// LastModifiedTimestamp tracks last time Status was updated
// +optional
LastModifiedTimestamp metav1.Time `json:"lastModifiedTimestamp,omitempty"`
}

// ConsumerForwardingRule is a reference to the PSC consumer forwarding rule
// +k8s:openapi-gen=true
type ConsumerForwardingRule struct {
// Forwarding rule consumer created to use ServiceAttachment
ForwardingRuleURL string `json:"forwardingRuleURL,omitempty"`

// Status of consumer forwarding rule
Status string `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ServiceAttachmentList is a list of ServiceAttachment resources
type ServiceAttachmentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []ServiceAttachment `json:"items"`
}

0 comments on commit fd41fb1

Please sign in to comment.