Skip to content

Commit

Permalink
Let the Operator get the VizierID and send to Config Manager Service (#…
Browse files Browse the repository at this point in the history
…1670)

Summary: This PR lets the operator get the VizierID from the cluster's
secrets and then sends it to the config manager service for it to
ultimately set feature flags.

Relevant Issues: Fixes #1632

Type of change: /kind bug

Test Plan: Skaffold the cloud changes on the testing cluster and then
skaffold the operator changes on a dev cluster. Manually trigger an
update on the operator side to send the VizierID to the config manager
service. Check the config manager service's logs to see that the new
logic is being executed as expected to handle the VizierID.

---------

Signed-off-by: Kartik Pattaswamy <kpattaswamy@pixielabs.ai>
  • Loading branch information
kpattaswamy authored Aug 16, 2023
1 parent e5d83b7 commit c9813f7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/operator/controllers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//src/api/proto/cloudpb:cloudapi_pl_go_proto",
"//src/api/proto/uuidpb:uuid_pl_go_proto",
"//src/api/proto/vizierconfigpb:vizier_pl_go_proto",
"//src/operator/apis/px.dev/v1alpha1",
"//src/shared/goversion",
"//src/shared/services",
"//src/shared/status",
"//src/utils",
"//src/utils/shared/certs",
"//src/utils/shared/k8s",
"@com_github_blang_semver//:semver",
Expand Down
44 changes: 42 additions & 2 deletions src/operator/controllers/vizier_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"px.dev/pixie/src/api/proto/cloudpb"
"px.dev/pixie/src/api/proto/uuidpb"
"px.dev/pixie/src/api/proto/vizierconfigpb"
"px.dev/pixie/src/operator/apis/px.dev/v1alpha1"
version "px.dev/pixie/src/shared/goversion"
"px.dev/pixie/src/shared/services"
"px.dev/pixie/src/shared/status"
"px.dev/pixie/src/utils"
"px.dev/pixie/src/utils/shared/certs"
"px.dev/pixie/src/utils/shared/k8s"
)
Expand Down Expand Up @@ -491,7 +493,13 @@ func (r *VizierReconciler) deployVizier(ctx context.Context, req ctrl.Request, v
return err
}

configForVizierResp, err := generateVizierYAMLsConfig(ctx, req.Namespace, r.K8sVersion, vz, cloudClient)
// Get the Vizier's ID from the cluster's secrets.
vizierID, err := getVizierID(r.Clientset, req.Namespace)
if err != nil {
log.WithError(err).Error("Failed to retrieve the Vizier ID from the cluster's secrets")
}

configForVizierResp, err := generateVizierYAMLsConfig(ctx, req.Namespace, r.K8sVersion, vizierID, vz, cloudClient)
if err != nil {
log.WithError(err).Error("Failed to generate configs for Vizier YAMLs")
return err
Expand Down Expand Up @@ -803,13 +811,14 @@ func convertResourceType(originalLst v1.ResourceList) *vizierconfigpb.ResourceLi

// generateVizierYAMLsConfig is responsible retrieving a yaml map of configurations from
// Pixie Cloud.
func generateVizierYAMLsConfig(ctx context.Context, ns string, k8sVersion string, vz *v1alpha1.Vizier, conn *grpc.ClientConn) (*cloudpb.ConfigForVizierResponse,
func generateVizierYAMLsConfig(ctx context.Context, ns string, k8sVersion string, vizierID *uuidpb.UUID, vz *v1alpha1.Vizier, conn *grpc.ClientConn) (*cloudpb.ConfigForVizierResponse,
error) {
client := cloudpb.NewConfigServiceClient(conn)

req := &cloudpb.ConfigForVizierRequest{
Namespace: ns,
K8sVersion: k8sVersion,
VizierID: vizierID,
VzSpec: &vizierconfigpb.VizierSpec{
Version: vz.Spec.Version,
DeployKey: vz.Spec.DeployKey,
Expand Down Expand Up @@ -1123,6 +1132,37 @@ func getClusterUID(clientset *kubernetes.Clientset) (string, error) {
return string(ksNS.UID), nil
}

// getVizierID gets the ID of the cluster the Vizier is in.
func getVizierID(clientset *kubernetes.Clientset, namespace string) (*uuidpb.UUID, error) {
op := func() (*uuidpb.UUID, error) {
var vizierID *uuidpb.UUID
s := k8s.GetSecret(clientset, namespace, "pl-cluster-secrets")
if s == nil {
return nil, errors.New("Missing cluster secrets, retrying again")
}
if id, ok := s.Data["cluster-id"]; ok {
vizierID = utils.ProtoFromUUIDStrOrNil(string(id))
if vizierID == nil {
return nil, errors.New("Couldn't convert ID to proto")
}
}

return vizierID, nil
}

expBackoff := backoff.NewExponentialBackOff()
expBackoff.InitialInterval = 10 * time.Second
expBackoff.Multiplier = 2
expBackoff.MaxElapsedTime = 10 * time.Minute

vizierID, err := backoff.RetryWithData(op, expBackoff)
if err != nil {
return nil, errors.New("Timed out waiting for the Vizier ID")
}

return vizierID, nil
}

// getConfigForOperator is responsible retrieving the Operator config from from Pixie Cloud.
func getConfigForOperator(ctx context.Context, conn *grpc.ClientConn) (*cloudpb.ConfigForOperatorResponse, error) {
client := cloudpb.NewConfigServiceClient(conn)
Expand Down

0 comments on commit c9813f7

Please sign in to comment.