-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(kuma-cp): allow to pass more apiWebServiceCustomize fns (#8439)
Signed-off-by: Bart Smykla <[email protected]>
- Loading branch information
1 parent
fd7f34d
commit a029ccb
Showing
6 changed files
with
145 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package runtime_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kumahq/kuma/pkg/test" | ||
) | ||
|
||
func TestRuntime(t *testing.T) { | ||
test.RunSpecs(t, "Runtime Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package runtime_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/emicklei/go-restful/v3" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
kuma_cp "github.com/kumahq/kuma/pkg/config/app/kuma-cp" | ||
test_api_server "github.com/kumahq/kuma/pkg/test/api_server" | ||
test_runtime "github.com/kumahq/kuma/pkg/test/runtime" | ||
) | ||
|
||
func return200ForPath(path string) func(ws *restful.WebService) error { | ||
return func(ws *restful.WebService) error { | ||
ws.Route( | ||
ws.GET(path).To(func(req *restful.Request, res *restful.Response) { | ||
res.WriteHeader(http.StatusOK) | ||
}), | ||
) | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var _ = Describe("APIWebServiceCustomize", func() { | ||
var stop chan struct{} | ||
|
||
AfterEach(func() { | ||
if stop != nil { | ||
close(stop) | ||
} | ||
}) | ||
|
||
It("should allow for multiple customization functions", func() { | ||
// given | ||
cfg := kuma_cp.DefaultConfig() | ||
cfg.ApiServer.HTTPS.Enabled = false | ||
cfg.ApiServer.HTTP.Interface = "127.0.0.1" | ||
builder, err := test_runtime.BuilderFor(context.Background(), cfg) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// when | ||
rt, err := builder. | ||
WithAPIWebServiceCustomize(return200ForPath("/foo")). | ||
WithAPIWebServiceCustomize(return200ForPath("/bar")). | ||
Build() | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
apiServer, err := test_api_server.NewApiServer(cfg, rt) | ||
Expect(err).To(Succeed()) | ||
|
||
stop = make(chan struct{}) | ||
go func() { | ||
defer GinkgoRecover() | ||
|
||
Expect(apiServer.Start(stop)).To(Succeed()) | ||
}() | ||
|
||
// then | ||
Eventually(func(g Gomega) { | ||
fooRes, err := http.Get("http://" + apiServer.Address() + "/foo") | ||
g.Expect(err).To(Succeed()) | ||
g.Expect(fooRes.StatusCode).To(Equal(http.StatusOK)) | ||
|
||
barRes, err := http.Get("http://" + apiServer.Address() + "/bar") | ||
g.Expect(err).To(Succeed()) | ||
g.Expect(barRes.StatusCode).To(Equal(http.StatusOK)) | ||
}).Should(Succeed()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package api_server | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/kumahq/kuma/pkg/api-server" | ||
"github.com/kumahq/kuma/pkg/config/app/kuma-cp" | ||
"github.com/kumahq/kuma/pkg/core/resources/model" | ||
"github.com/kumahq/kuma/pkg/core/resources/registry" | ||
"github.com/kumahq/kuma/pkg/core/runtime" | ||
"github.com/kumahq/kuma/pkg/dns/vips" | ||
"github.com/kumahq/kuma/pkg/xds/context" | ||
"github.com/kumahq/kuma/pkg/xds/server" | ||
) | ||
|
||
func NewApiServer(cfg kuma_cp.Config, runtime runtime.Runtime) (*api_server.ApiServer, error) { | ||
return api_server.NewApiServer( | ||
runtime.ResourceManager(), | ||
context.NewMeshContextBuilder( | ||
runtime.ResourceManager(), | ||
server.MeshResourceTypes(), | ||
net.LookupIP, | ||
cfg.Multizone.Zone.Name, | ||
vips.NewPersistence( | ||
runtime.ResourceManager(), | ||
runtime.ConfigManager(), | ||
cfg.Experimental.UseTagFirstVirtualOutboundModel, | ||
), | ||
cfg.DNSServer.Domain, | ||
cfg.DNSServer.ServiceVipPort, | ||
context.AnyToAnyReachableServicesGraphBuilder, | ||
), | ||
runtime.APIInstaller(), | ||
registry.Global().ObjectDescriptors(model.HasWsEnabled()), | ||
&cfg, | ||
runtime.Metrics(), | ||
runtime.GetInstanceId, | ||
runtime.GetClusterId, | ||
runtime.APIServerAuthenticator(), | ||
runtime.Access(), | ||
runtime.EnvoyAdminClient(), | ||
runtime.TokenIssuers(), | ||
runtime.APIWebServiceCustomize(), | ||
runtime.GlobalInsightService(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters