Skip to content

Commit

Permalink
deepcopy
Browse files Browse the repository at this point in the history
Signed-off-by: Shubham Chauhan <shubham@tetrate.io>
  • Loading branch information
chauhanshubham committed Nov 21, 2022
1 parent 367039b commit bfb22e5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 27 deletions.
27 changes: 1 addition & 26 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type InfraIRMap map[string]*ir.Infra

// Resources holds the Gateway API and related
// resources that the translators needs as inputs.
// +k8s:deepcopy-gen=true
type Resources struct {
Gateways []*v1beta1.Gateway
HTTPRoutes []*v1beta1.HTTPRoute
Expand All @@ -58,32 +59,6 @@ type Resources struct {
Secrets []*v1.Secret
}

func (r *Resources) DeepCopy() *Resources {
resourcesCopy := new(Resources)
for _, i := range r.Gateways {
resourcesCopy.Gateways = append(resourcesCopy.Gateways, i.DeepCopy())
}
for _, i := range r.HTTPRoutes {
resourcesCopy.HTTPRoutes = append(resourcesCopy.HTTPRoutes, i.DeepCopy())
}
for _, i := range r.TLSRoutes {
resourcesCopy.TLSRoutes = append(resourcesCopy.TLSRoutes, i.DeepCopy())
}
for _, i := range r.ReferenceGrants {
resourcesCopy.ReferenceGrants = append(resourcesCopy.ReferenceGrants, i.DeepCopy())
}
for _, i := range r.Namespaces {
resourcesCopy.Namespaces = append(resourcesCopy.Namespaces, i.DeepCopy())
}
for _, i := range r.Services {
resourcesCopy.Services = append(resourcesCopy.Services, i.DeepCopy())
}
for _, i := range r.Secrets {
resourcesCopy.Secrets = append(resourcesCopy.Secrets, i.DeepCopy())
}
return resourcesCopy
}

func (r *Resources) GetNamespace(name string) *v1.Namespace {
for _, ns := range r.Namespaces {
if ns.Name == name {
Expand Down
109 changes: 109 additions & 0 deletions internal/gatewayapi/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion tools/make/kube.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ manifests: $(tools/controller-gen) ## Generate WebhookConfiguration, ClusterRole
.PHONY: generate
generate: $(tools/controller-gen) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
# Note that the paths can't just be "./..." with the header file, or the tool will panic on run. Sorry.
$(tools/controller-gen) $(CONTROLLERGEN_OBJECT_FLAGS) paths="{$(ROOT_DIR)/api/config/...,$(ROOT_DIR)/internal/ir/...}"
$(tools/controller-gen) $(CONTROLLERGEN_OBJECT_FLAGS) paths="{$(ROOT_DIR)/api/config/...,$(ROOT_DIR)/internal/ir/...,$(ROOT_DIR)/internal/gatewayapi/...}"

.PHONY: kube-test
kube-test: manifests generate $(tools/setup-envtest) ## Run Kubernetes provider tests.
Expand Down

0 comments on commit bfb22e5

Please sign in to comment.