Skip to content

Commit 31616dd

Browse files
committed
Initial commit for gce provider.
1 parent 825f587 commit 31616dd

File tree

6 files changed

+214
-0
lines changed

6 files changed

+214
-0
lines changed

cmd/print.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
// Call init function for the providers
3131
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/apisix"
32+
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/gce"
3233
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/ingressnginx"
3334
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/istio"
3435
_ "github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw/providers/kong"

pkg/i2gw/providers/gce/converter.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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 gce
18+
19+
import (
20+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
21+
)
22+
23+
// converter implements the ToGatewayAPI function of i2gw.ResourceConverter interface.
24+
type converter struct {
25+
conf *i2gw.ProviderConf
26+
27+
featureParsers []i2gw.FeatureParser
28+
implementationSpecificOptions i2gw.ProviderImplementationSpecificOptions
29+
}
30+
31+
// newConverter returns an ingress-gce converter instance.
32+
func newConverter(conf *i2gw.ProviderConf) converter {
33+
return converter{
34+
conf: conf,
35+
featureParsers: []i2gw.FeatureParser{
36+
// The list of feature parsers comes here.
37+
},
38+
implementationSpecificOptions: i2gw.ProviderImplementationSpecificOptions{
39+
// The list of the implementationSpecific ingress fields options comes here.
40+
},
41+
}
42+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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 gce

pkg/i2gw/providers/gce/gce.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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 gce
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
24+
"k8s.io/apimachinery/pkg/util/validation/field"
25+
)
26+
27+
// The ProviderName returned to the provider's registry.
28+
const ProviderName = "gce"
29+
30+
func init() {
31+
i2gw.ProviderConstructorByName[ProviderName] = NewProvider
32+
}
33+
34+
// Provider implements the i2gw.Provider interface.
35+
type Provider struct {
36+
storage *storage
37+
reader reader
38+
converter converter
39+
}
40+
41+
// NewProvider constructs and returns the example-gateway implementation of i2gw.Provider.
42+
func NewProvider(conf *i2gw.ProviderConf) i2gw.Provider {
43+
return &Provider{
44+
storage: newResourcesStorage(),
45+
reader: newResourceReader(conf),
46+
converter: newConverter(conf),
47+
}
48+
}
49+
50+
func (p *Provider) ReadResourcesFromCluster(ctx context.Context) error {
51+
storage, err := p.reader.readResourcesFromCluster(ctx)
52+
if err != nil {
53+
return fmt.Errorf("failed to read resources from cluster: %w", err)
54+
}
55+
56+
p.storage = storage
57+
return nil
58+
}
59+
60+
func (p *Provider) ReadResourcesFromFile(ctx context.Context, filename string) error {
61+
storage, err := p.reader.readResourcesFromFile(ctx, filename)
62+
if err != nil {
63+
return fmt.Errorf("failed to read resources from file: %w", err)
64+
}
65+
p.storage = storage
66+
return nil
67+
}
68+
69+
// ToGatewayAPI converts stored Ingress GCE API entities to
70+
// i2gw.GatewayResources including the ingress-gce specific features.
71+
func (p *Provider) ToGatewayAPI() (i2gw.GatewayResources, field.ErrorList) {
72+
return p.converter.convert(p.storage)
73+
}
74+
75+
func (c *converter) convert(storage *storage) (i2gw.GatewayResources, field.ErrorList) {
76+
return i2gw.GatewayResources{}, field.ErrorList{}
77+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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 gce
18+
19+
import (
20+
"context"
21+
22+
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
23+
)
24+
25+
// converter implements the i2gw.CustomResourceReader interface.
26+
type reader struct {
27+
conf *i2gw.ProviderConf
28+
}
29+
30+
// newResourceReader returns a resourceReader instance.
31+
func newResourceReader(conf *i2gw.ProviderConf) reader {
32+
return reader{
33+
conf: conf,
34+
}
35+
}
36+
37+
func (r *reader) readResourcesFromCluster(ctx context.Context) (*storage, error) {
38+
// read example-gateway related resources from the cluster.
39+
return nil, nil
40+
}
41+
42+
func (r *reader) readResourcesFromFile(ctx context.Context, filename string) (*storage, error) {
43+
// read example-gateway related resources from the file.
44+
return nil, nil
45+
}

pkg/i2gw/providers/gce/storage.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2024 The Kubernetes 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 gce
18+
19+
import (
20+
networkingv1 "k8s.io/api/networking/v1"
21+
"k8s.io/apimachinery/pkg/types"
22+
)
23+
24+
type storage struct {
25+
Ingresses map[types.NamespacedName]*networkingv1.Ingress
26+
}
27+
28+
func newResourcesStorage() *storage {
29+
return &storage{
30+
Ingresses: map[types.NamespacedName]*networkingv1.Ingress{},
31+
}
32+
}

0 commit comments

Comments
 (0)