Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace gogoprotobuf with golang protobuf #8949

Merged
merged 47 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7b08a24
Use google.golang.org/protobuf
hjiawei Jan 28, 2024
8b57312
updated ID types for mock dataplane
hda2 Jun 28, 2024
2f058fd
convert proto type IDs to be valid map keys
hda2 Jun 29, 2024
cdddfa8
solved copylocks warning by passing proto type reference
hda2 Jun 30, 2024
41fd58f
make all processor unit tests passed
hda2 Jul 2, 2024
9e9027f
convert proto types for app-policy
hda2 Jul 4, 2024
6710a7c
convert proto types for mock dataplane
hda2 Jul 5, 2024
6196ed3
addressed hjiawei's comments
hda2 Jul 5, 2024
3b960b0
make all TestCalculationGraph unit tests passed
hda2 Jul 7, 2024
212811b
fixed linter copylocks issues part 1
hda2 Jul 8, 2024
e4ad9f8
fixed linter copylocks issue part 2
hda2 Jul 8, 2024
0a28f6b
replace deprecated grpc.Dial by grpc.NewClient
hda2 Jul 8, 2024
1e859c1
resovled conflict issues due to rebase
hda2 Jul 8, 2024
c932f81
set default resolver scheme passthrough before grpc.NewClient for UNI…
hda2 Jul 9, 2024
2c9ff39
Re-generate protobuf and cleanup go.mod
hjiawei Jul 9, 2024
72bea90
fixed syncserver_test and policysync_test issues
hda2 Jul 9, 2024
e105a42
fixed policysync_test nsID issue
hda2 Jul 9, 2024
27fda13
addressed hjiawei's comments
hda2 Jul 9, 2024
26dcce4
addressed hjiawei's comments: updated file names
hda2 Jul 9, 2024
c9d170b
fixed policysync_test which tried to compare two proto objs by using …
hda2 Jul 9, 2024
a749e78
fixed static checks ineffectual assignment for equal
hda2 Jul 9, 2024
ff60532
fixed policysync_test index value issue
hda2 Jul 10, 2024
1d4a50a
fixed the panic issue when proto.RouteUpdate try to access Type
hda2 Jul 10, 2024
6c94188
addressed hjiawei's comment: should use Eventrually for async assertion
hda2 Jul 10, 2024
2af03f6
Use one line Expect googleproto equal to be true
hjiawei Jul 12, 2024
f34fe41
Add Expect assertion
hjiawei Jul 12, 2024
4cf0d48
Move grpc resolver SetDefaultScheme to init func
hjiawei Jul 12, 2024
f0a4d9e
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Jul 13, 2024
e5691f8
Merge branch 'master' into hda2/protoc-update-map-keys
hda2 Aug 2, 2024
512edde
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Aug 8, 2024
813995c
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Aug 9, 2024
fe9d78d
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Sep 14, 2024
7dd14d6
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Oct 30, 2024
22a5e5e
Fix app-policy checker unit tests
hjiawei Oct 30, 2024
9b4febd
Fix felix calc state unit tests
hjiawei Oct 30, 2024
6cf322a
Add protobuf target for pod2daemon and remove SKIP_PROTOBUF flag
hjiawei Oct 31, 2024
868479a
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Nov 15, 2024
190b4c5
Fix go import format
hjiawei Nov 15, 2024
7c09a4e
Use make fix-changed to reformat generated go files
hjiawei Nov 15, 2024
96df8e0
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Nov 15, 2024
819a2ce
Revert back to make fix for api
hjiawei Nov 15, 2024
f2f099c
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Nov 16, 2024
c2da740
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Dec 5, 2024
fb85757
Merge remote-tracking branch 'upstream/master' into hda2/protoc-updat…
hjiawei Dec 13, 2024
9065841
Merge branch 'master' of https://github.com/projectcalico/calico into…
hda2 Dec 21, 2024
3da8bf9
Update go mod
hda2 Dec 21, 2024
ac5f3f2
Fix felix untracked policy unit tests
hda2 Dec 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .semaphore/semaphore-scheduled-builds.yml

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

8 changes: 3 additions & 5 deletions .semaphore/semaphore.yml

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

8 changes: 3 additions & 5 deletions .semaphore/semaphore.yml.d/blocks/20-felix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@
- s390x
commands:
# Only building the code, not the image here because the felix image is now only used for FV tests, which
# only run on AMD64 at the moment. Skip building protofbufs because the build fails on ARM due to missing
# image. We know they are up-to-date because an earlier build job checks already.
- ../.semaphore/run-and-monitor build-$ARCH.log make build ARCH=$ARCH SKIP_PROTOBUF=true
# only run on AMD64 at the moment.
- ../.semaphore/run-and-monitor build-$ARCH.log make build ARCH=$ARCH
- name: "Felix: Build - native arm64 runner"
run:
when: "${FORCE_RUN} or change_in(['/*', '/api/', '/libcalico-go/', '/typha/', '/felix/'], {exclude: ['/**/.gitignore', '/**/README.md', '/**/LICENSE']})"
Expand All @@ -75,8 +74,7 @@
jobs:
- name: Build binary
commands:
# Skipping protobuf build because it fails on ARM (but the pre-flight check ensures it's up-to-date).
- ../.semaphore/run-and-monitor build-arm64.log make build ARCH=arm64 SKIP_PROTOBUF=true
- ../.semaphore/run-and-monitor build-arm64.log make build ARCH=arm64
- name: "Felix: Build Windows binaries"
run:
when: "${FORCE_RUN} or change_in(['/*', '/api/', '/libcalico-go/', '/typha/', '/felix/'], {exclude: ['/**/.gitignore', '/**/README.md', '/**/LICENSE']})"
Expand Down
18 changes: 3 additions & 15 deletions app-policy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,12 @@ endif
../felix/proto/felixbackend.pb.go: ../felix/proto/felixbackend.proto
$(MAKE) --directory ../felix protobuf

# We use gogofast for protobuf compilation. Regular gogo is incompatible with
# gRPC, since gRPC uses golang/protobuf for marshalling/unmarshalling in that
# case. See https://github.com/gogo/protobuf/issues/386 for more details.
# Note that we cannot seem to use gogofaster because of incompatibility with
# Envoy's validation library.
# When importing, we must use gogo versions of google/protobuf and
# google/rpc (aka googleapis).
PROTOC_IMPORTS = -I proto\
-I ./

protobuf: $(GENERATED_FILES)

proto/healthz.pb.go: proto/healthz.proto
$(DOCKER_RUN) -v $(CURDIR):/src:rw --user $(LOCAL_USER_ID):$(LOCAL_GROUP_ID) \
$(PROTOC_CONTAINER) \
$(PROTOC_IMPORTS) \
proto/*.proto \
--gogofast_out=plugins=grpc:proto
$(DOCKER_RUN) -v $(CURDIR)/proto:/proto:rw \
$(CALICO_BUILD) \
sh -c 'protoc --proto_path=/proto --go_out=/proto --go-grpc_out=. --go_opt=paths=source_relative healthz.proto'
$(MAKE) fix-changed


Expand Down
5 changes: 3 additions & 2 deletions app-policy/checker/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/projectcalico/calico/app-policy/policystore"
"github.com/projectcalico/calico/felix/proto"
"github.com/projectcalico/calico/felix/types"
)

var OK = int32(code.Code_OK)
Expand Down Expand Up @@ -89,7 +90,7 @@ func checkTiers(store *policystore.PolicyStore, ep *proto.WorkloadEndpoint, req
action := NO_MATCH
Policy:
for i, name := range policies {
pID := proto.PolicyID{Tier: tier.GetName(), Name: name}
pID := types.PolicyID{Tier: tier.GetName(), Name: name}
policy := store.PolicyByID[pID]
action = checkPolicy(policy, reqCache)
log.Debugf("Policy checked (ordinal=%d, profileId=%v, action=%v)", i, pID, action)
Expand Down Expand Up @@ -126,7 +127,7 @@ func checkTiers(store *policystore.PolicyStore, ep *proto.WorkloadEndpoint, req
// If we reach here, there were either no tiers, or a policy PASSed the request.
if len(ep.ProfileIds) > 0 {
for i, name := range ep.ProfileIds {
pID := proto.ProfileID{Name: name}
pID := types.ProfileID{Name: name}
profile := store.ProfileByID[pID]
action := checkProfile(profile, reqCache)
log.Debugf("Profile checked (ordinal=%d, profileId=%v, action=%v)", i, pID, action)
Expand Down
46 changes: 22 additions & 24 deletions app-policy/checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"testing"

authz "github.com/envoyproxy/go-control-plane/envoy/service/auth/v3"
"github.com/gogo/googleapis/google/rpc"
. "github.com/onsi/gomega"

"github.com/projectcalico/calico/app-policy/policystore"
"github.com/projectcalico/calico/felix/proto"
"github.com/projectcalico/calico/felix/types"
)

// actionFromString should parse strings in case-insensitive mode.
Expand Down Expand Up @@ -123,21 +123,21 @@ func TestCheckNoIngressPolicyRulesInTier(t *testing.T) {
},
ProfileIds: []string{"profile1"},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
OutboundRules: []*proto.Rule{
{
Action: "allow",
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
OutboundRules: []*proto.Rule{
{
Action: "allow",
},
},
}
store.ProfileByID[proto.ProfileID{Name: "profile1"}] = &proto.Profile{
store.ProfileByID[types.ProfileID{Name: "profile1"}] = &proto.Profile{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand All @@ -158,9 +158,7 @@ func TestCheckNoIngressPolicyRulesInTier(t *testing.T) {
}}

status := checkTiers(store, store.Endpoint, req)
expectedStatus := rpc.Status{Code: OK}
Expect(status.Code).To(Equal(expectedStatus.Code))
Expect(status.Message).To(Equal(expectedStatus.Message))
Expect(status.Code).To(Equal(OK))
Expect(status.Details).To(BeNil())
}

Expand Down Expand Up @@ -220,15 +218,15 @@ func TestCheckStorePolicyMatch(t *testing.T) {
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "deny",
HttpMatch: &proto.HTTPMatch{Methods: []string{"HEAD"}},
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down Expand Up @@ -268,15 +266,15 @@ func TestCheckStoreProfileOnly(t *testing.T) {
Tiers: []*proto.TierInfo{},
ProfileIds: []string{"profile1", "profile2"},
}
store.ProfileByID[proto.ProfileID{Name: "profile1"}] = &proto.Profile{
store.ProfileByID[types.ProfileID{Name: "profile1"}] = &proto.Profile{
InboundRules: []*proto.Rule{
{
Action: "Deny",
HttpMatch: &proto.HTTPMatch{Methods: []string{"HEAD"}},
},
},
}
store.ProfileByID[proto.ProfileID{Name: "profile2"}] = &proto.Profile{
store.ProfileByID[types.ProfileID{Name: "profile2"}] = &proto.Profile{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down Expand Up @@ -321,15 +319,15 @@ func TestCheckStorePolicyDefaultDeny(t *testing.T) {
},
ProfileIds: []string{"profile1"},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "deny",
HttpMatch: &proto.HTTPMatch{Methods: []string{"HEAD"}},
},
},
}
store.ProfileByID[proto.ProfileID{Name: "profile1"}] = &proto.Profile{
store.ProfileByID[types.ProfileID{Name: "profile1"}] = &proto.Profile{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down Expand Up @@ -368,15 +366,15 @@ func TestCheckStorePass(t *testing.T) {
}

// Policy1 matches and has action PASS, which means policy2 is not evaluated.
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "next-tier",
HttpMatch: &proto.HTTPMatch{Methods: []string{"GET"}},
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "deny",
Expand All @@ -386,7 +384,7 @@ func TestCheckStorePass(t *testing.T) {
}

// Profile1 matches and allows the traffic.
store.ProfileByID[proto.ProfileID{Name: "profile1"}] = &proto.Profile{
store.ProfileByID[types.ProfileID{Name: "profile1"}] = &proto.Profile{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down Expand Up @@ -448,7 +446,7 @@ func TestCheckStoreWithInvalidData(t *testing.T) {
}},
ProfileIds: []string{"profile1"},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{InboundRules: []*proto.Rule{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{InboundRules: []*proto.Rule{
{
Action: "allow",
HttpMatch: &proto.HTTPMatch{
Expand Down Expand Up @@ -498,15 +496,15 @@ func TestCheckStorePolicyMultiTierMatch(t *testing.T) {
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "next-tier",
HttpMatch: &proto.HTTPMatch{Methods: []string{"GET", "HEAD"}},
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier2", Name: "policy2"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier2", Name: "policy2"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "deny",
Expand All @@ -516,7 +514,7 @@ func TestCheckStorePolicyMultiTierMatch(t *testing.T) {
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier2", Name: "policy3"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier2", Name: "policy3"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand All @@ -526,7 +524,7 @@ func TestCheckStorePolicyMultiTierMatch(t *testing.T) {
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier3", Name: "policy4"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier3", Name: "policy4"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down Expand Up @@ -584,23 +582,23 @@ func TestCheckStorePolicyMultiTierDiffTierMatch(t *testing.T) {
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy1"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "deny",
HttpMatch: &proto.HTTPMatch{Methods: []string{"HEAD"}},
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier1", Name: "policy2"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "next-tier",
HttpMatch: &proto.HTTPMatch{Methods: []string{"GET"}},
},
},
}
store.PolicyByID[proto.PolicyID{Tier: "tier2", Name: "policy3"}] = &proto.Policy{
store.PolicyByID[types.PolicyID{Tier: "tier2", Name: "policy3"}] = &proto.Policy{
InboundRules: []*proto.Rule{
{
Action: "allow",
Expand Down
11 changes: 7 additions & 4 deletions app-policy/checker/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/projectcalico/calico/app-policy/policystore"
"github.com/projectcalico/calico/felix/proto"
"github.com/projectcalico/calico/felix/types"
)

var (
Expand Down Expand Up @@ -351,10 +352,12 @@ func TestMatchRuleNamespaceSelectors(t *testing.T) {
}}

store := policystore.NewPolicyStore()
id := proto.NamespaceID{Name: "src"}
store.NamespaceByID[id] = &proto.NamespaceUpdate{Id: &id, Labels: map[string]string{"place": "src"}}
id = proto.NamespaceID{Name: "dst"}
store.NamespaceByID[id] = &proto.NamespaceUpdate{Id: &id, Labels: map[string]string{"place": "dst"}}
id := types.NamespaceID{Name: "src"}
protoID := types.NamespaceIDToProto(id)
store.NamespaceByID[id] = &proto.NamespaceUpdate{Id: protoID, Labels: map[string]string{"place": "src"}}
id = types.NamespaceID{Name: "dst"}
protoID = types.NamespaceIDToProto(id)
store.NamespaceByID[id] = &proto.NamespaceUpdate{Id: protoID, Labels: map[string]string{"place": "dst"}}
reqCache, err := NewRequestCache(store, req)
Expect(err).To(Succeed())
Expect(match(rule, reqCache, "")).To(BeTrue())
Expand Down
6 changes: 3 additions & 3 deletions app-policy/checker/requestcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/projectcalico/calico/app-policy/policystore"
"github.com/projectcalico/calico/felix/proto"
"github.com/projectcalico/calico/felix/types"
)

// requestCache contains the CheckRequest and cached copies of computed information about the request
Expand Down Expand Up @@ -119,7 +119,7 @@ func (r *requestCache) initPeer(aPeer *authz.AttributeContext_Peer) (*peer, erro
}

// If the service account is in the store, copy labels over.
id := proto.ServiceAccountID{Name: peer.Name, Namespace: peer.Namespace}
id := types.ServiceAccountID{Name: peer.Name, Namespace: peer.Namespace}
msg, ok := r.store.ServiceAccountByID[id]
if ok {
for k, v := range msg.GetLabels() {
Expand All @@ -132,7 +132,7 @@ func (r *requestCache) initPeer(aPeer *authz.AttributeContext_Peer) (*peer, erro
func (r *requestCache) initNamespace(name string) *namespace {
ns := &namespace{Name: name}
// If the namespace is in the store, copy labels over.
id := proto.NamespaceID{Name: name}
id := types.NamespaceID{Name: name}
msg, ok := r.store.NamespaceByID[id]
if ok {
ns.Labels = make(map[string]string)
Expand Down
Loading
Loading