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

[1.13] cli: Infer gloo deploy name #9719

Merged
merged 5 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
5 changes: 5 additions & 0 deletions changelog/v1.13.39/infer-gloo-deploy-name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/gloo/issues/9163
resolvesIssue: false
description: Infer the gloo deployment name in cases where the deployment name is not the default `gloo`. The gloo deployment is identified by the `gloo=gloo` label.
9 changes: 6 additions & 3 deletions projects/gloo/cli/pkg/cmd/check/gloo_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var (
return fmt.Sprintf("Gloo has detected that the data plane is out of sync. The following types of resources have not been accepted: %v. "+
"Gloo will not be able to process any other configuration updates until these errors are resolved.", resourceNames)
}

// Initialize the custom deployment name that is overwritten later on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
// Initialize the custom deployment name that is overwritten later on
// Initialize the custom deployment name that is overwritten later on in the `CheckResources` function

customGlooDeploymentName = glooDeployment
)

func ResourcesSyncedOverXds(stats, deploymentName string) bool {
Expand Down Expand Up @@ -78,7 +81,7 @@ func checkXdsMetrics(opts *options.Options, glooNamespace string, deployments *v
localPort := strconv.Itoa(freePort)
adminPort := strconv.Itoa(int(defaults.GlooAdminPort))
// stats is the string containing all stats from /stats/prometheus
stats, portFwdCmd, err := cliutil.PortForwardGet(opts.Top.Ctx, glooNamespace, "deploy/"+glooDeployment,
stats, portFwdCmd, err := cliutil.PortForwardGet(opts.Top.Ctx, glooNamespace, "deploy/"+customGlooDeploymentName,
localPort, adminPort, false, glooStatsPath)
if err != nil {
return err
Expand All @@ -89,12 +92,12 @@ func checkXdsMetrics(opts *options.Options, glooNamespace string, deployments *v
}

if strings.TrimSpace(stats) == "" {
err := fmt.Sprint(errMessage+": could not find any metrics at", glooStatsPath, "endpoint of the "+glooDeployment+" deployment")
err := fmt.Sprint(errMessage+": could not find any metrics at", glooStatsPath, "endpoint of the "+customGlooDeploymentName+" deployment")
fmt.Println(err)
return fmt.Errorf(err)
}

if !ResourcesSyncedOverXds(stats, glooDeployment) {
if !ResourcesSyncedOverXds(stats, customGlooDeploymentName) {
fmt.Println(errMessage)
return fmt.Errorf(errMessage)
}
Expand Down
7 changes: 7 additions & 0 deletions projects/gloo/cli/pkg/cmd/check/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ func CheckResources(opts *options.Options) error {
multiErr = multierror.Append(multiErr, err)
}
}
// Fetch the gloo deployment name even if check deployments is disabled as it is used in other checks
customGlooDeploymentName, err = helpers.GetGlooDeploymentName(opts.Top.Ctx, opts.Metadata.GetNamespace())
if err != nil {
multiErr = multierror.Append(multiErr, err)
// Fallback to the default deployment name if unable to fetch the custom one
customGlooDeploymentName = glooDeployment
}

if included := doesNotContain(opts.Top.CheckName, "pods"); included {
err := checkPods(ctx, opts)
Expand Down
12 changes: 12 additions & 0 deletions projects/gloo/cli/pkg/cmd/check/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ var _ = Describe("Root", func() {
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: "gloo-system",
Labels: map[string]string{
"gloo": "gloo",
},
},
Spec: appsv1.DeploymentSpec{},
}, metav1.CreateOptions{})
Expand Down Expand Up @@ -95,6 +98,9 @@ var _ = Describe("Root", func() {
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: "gloo-system",
Labels: map[string]string{
"gloo": "gloo",
},
},
Spec: appsv1.DeploymentSpec{},
}, metav1.CreateOptions{})
Expand Down Expand Up @@ -176,6 +182,9 @@ var _ = Describe("Root", func() {
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: myNs,
Labels: map[string]string{
"gloo": "gloo",
},
},
Spec: appsv1.DeploymentSpec{},
}, metav1.CreateOptions{})
Expand Down Expand Up @@ -221,6 +230,9 @@ var _ = Describe("Root", func() {
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: "gloo-system",
Labels: map[string]string{
"gloo": "gloo",
},
},
Spec: appsv1.DeploymentSpec{},
}, metav1.CreateOptions{})
Expand Down
7 changes: 6 additions & 1 deletion projects/gloo/cli/pkg/common/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func getProxiesFromK8s(name string, opts *options.Options) (gloov1.ProxyList, er
// if name is empty, return all proxies
func getProxiesFromGrpc(name string, namespace string, opts *options.Options, proxyEndpointPort string) (gloov1.ProxyList, error) {

glooDeploymentName, err := helpers.GetGlooDeploymentName(opts.Top.Ctx, opts.Metadata.GetNamespace())
if err != nil {
return nil, err
}

options := []grpc.CallOption{
// Some proxies can become very large and exceed the default 100Mb limit
// For this reason we want remove the limit but will settle for a limit of MaxInt32
Expand All @@ -198,7 +203,7 @@ func getProxiesFromGrpc(name string, namespace string, opts *options.Options, pr
return nil, err
}
localPort := strconv.Itoa(freePort)
portFwdCmd, err := cliutil.PortForward(opts.Metadata.GetNamespace(), "deployment/gloo",
portFwdCmd, err := cliutil.PortForward(opts.Metadata.GetNamespace(), "deployment/"+glooDeploymentName,
localPort, proxyEndpointPort, opts.Top.Verbose)
if portFwdCmd.Process != nil {
defer portFwdCmd.Process.Release()
Expand Down
27 changes: 27 additions & 0 deletions projects/gloo/cli/pkg/helpers/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ func KubeClient() (kubernetes.Interface, error) {
return clientset, nil
}

func GetGlooDeploymentName(ctx context.Context, namespace string) (string, error) {
client, err := KubeClient()
if err != nil {
errMessage := "error getting KubeClient"
fmt.Println(errMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: caller should be responsible for logging the error.

Fine with leaving it here but could we use contextutils.LoggerFrom to get the logger?

return "", fmt.Errorf(errMessage+": %v", err)
}
_, err = client.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{})
if err != nil {
errMessage := "Gloo namespace does not exist"
fmt.Println(errMessage)
return "", fmt.Errorf(errMessage+": %v", err)
}
deployments, err := client.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{
LabelSelector: "gloo=gloo",
})
if err != nil {
return "", err
}
if len(deployments.Items) != 1 {
errMessage := "Unable to find the gloo deployment"
fmt.Println(errMessage)
return "", fmt.Errorf(errMessage+": %v", err)
}
return deployments.Items[0].Name, nil
davidjumani marked this conversation as resolved.
Show resolved Hide resolved
}

func MustGetNamespaces(ctx context.Context) []string {
ns, err := GetNamespaces(ctx)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion projects/gloo/cli/pkg/xdsinspection/get_last_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
structpb "github.com/golang/protobuf/ptypes/struct"
"github.com/rotisserie/eris"
_ "github.com/solo-io/gloo/projects/envoyinit/hack/filter_types"
"github.com/solo-io/gloo/projects/gloo/cli/pkg/helpers"
"github.com/solo-io/gloo/projects/gloo/pkg/defaults"
"github.com/solo-io/go-utils/contextutils"
"go.uber.org/zap"
Expand All @@ -38,14 +39,19 @@ const (

func GetGlooXdsDump(ctx context.Context, proxyName, namespace string, verboseErrors bool) (*XdsDump, error) {

glooDeploymentName, err := helpers.GetGlooDeploymentName(ctx, namespace)
if err != nil {
return nil, err
}

xdsPort := strconv.Itoa(int(defaults.GlooXdsPort))
// If gloo is in MTLS mode
glooMtlsCheck := exec.Command("kubectl", "get", "configmap", envoySidecarConfig, "-n", namespace)
if err := glooMtlsCheck.Run(); err == nil {
xdsPort = strconv.Itoa(int(defaults.GlooMtlsModeXdsPort))
}
portFwd := exec.Command("kubectl", "port-forward", "-n", namespace,
"deployment/gloo", xdsPort)
"deployment/"+glooDeploymentName, xdsPort)
mergedPortForwardOutput := bytes.NewBuffer([]byte{})
portFwd.Stdout = mergedPortForwardOutput
portFwd.Stderr = mergedPortForwardOutput
Expand Down
Loading