mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-24 10:28:32 +00:00
* feat: add GatewayClass analyser Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * chore: add a valid GW class object Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * feat: add gw analyzer and switch to controller-runtime client Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * chore: add unit tests for gw analyser Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * chore: replace constants with condition status Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * feat: add httproute analyzer Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * feat: add HTTPRoute individual tests. Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> * docs: add analyzers Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> --------- Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> Signed-off-by: Aris Boutselis <aris.boutselis@senseon.io> Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
package analyzer
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/common"
|
|
"github.com/k8sgpt-ai/k8sgpt/pkg/kubernetes"
|
|
"github.com/stretchr/testify/assert"
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
|
|
gtwapi "sigs.k8s.io/gateway-api/apis/v1"
|
|
)
|
|
|
|
// Testing with the fake dynamic client if GatewayClasses have an accepted status
|
|
func TestGatewayClassAnalyzer(t *testing.T) {
|
|
GatewayClass := >wapi.GatewayClass{}
|
|
GatewayClass.Name = "foobar"
|
|
GatewayClass.Spec.ControllerName = "gateway.fooproxy.io/gatewayclass-controller"
|
|
// Initialize Conditions slice before setting properties
|
|
BadCondition := metav1.Condition{
|
|
Type: "Accepted",
|
|
Status: "Uknown",
|
|
Message: "Waiting for controller",
|
|
Reason: "Pending",
|
|
}
|
|
GatewayClass.Status.Conditions = []metav1.Condition{BadCondition}
|
|
// Create a GatewayClassAnalyzer instance with the fake client
|
|
scheme := scheme.Scheme
|
|
gtwapi.Install(scheme)
|
|
apiextensionsv1.AddToScheme(scheme)
|
|
|
|
fakeClient := fakeclient.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(GatewayClass).Build()
|
|
|
|
analyzerInstance := GatewayClassAnalyzer{}
|
|
config := common.Analyzer{
|
|
Client: &kubernetes.Client{
|
|
CtrlClient: fakeClient,
|
|
},
|
|
Context: context.Background(),
|
|
Namespace: "default",
|
|
}
|
|
analysisResults, err := analyzerInstance.Analyze(config)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
assert.Equal(t, len(analysisResults), 1)
|
|
|
|
}
|