-
Notifications
You must be signed in to change notification settings - Fork 73
[Feature] Add Gateway Config condition #1959
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
Changes from all commits
9a6b618
e68d735
e95e299
cdcba7d
e721417
55c6fe2
da36b24
c77c084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2025 ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// | ||
|
||
package client | ||
|
||
import ( | ||
"context" | ||
goHttp "net/http" | ||
|
||
utilConstants "github.com/arangodb/kube-arangodb/pkg/util/constants" | ||
) | ||
|
||
type Inventory struct { | ||
Configuration InventoryConfiguration `json:"configuration"` | ||
} | ||
|
||
type InventoryConfiguration struct { | ||
Hash string `json:"hash"` | ||
} | ||
|
||
func (c *client) Inventory(ctx context.Context) (*Inventory, error) { | ||
req, err := c.c.NewRequest(goHttp.MethodGet, utilConstants.EnvoyInventoryConfigDestination) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := c.c.Do(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := resp.CheckStatus(goHttp.StatusOK); err != nil { | ||
return nil, err | ||
} | ||
|
||
var l Inventory | ||
|
||
if err := resp.ParseBody("", &l); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &l, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// DISCLAIMER | ||
// | ||
// Copyright 2025 ArangoDB GmbH, Cologne, Germany | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
// | ||
|
||
package reconcile | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
core "k8s.io/api/core/v1" | ||
|
||
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" | ||
client "github.com/arangodb/kube-arangodb/pkg/deployment/client" | ||
sharedReconcile "github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared" | ||
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil" | ||
) | ||
|
||
func (r *Reconciler) createMemberGatewayConfigConditionPlan(ctx context.Context, _ k8sutil.APIObject, _ api.DeploymentSpec, | ||
status api.DeploymentStatus, planCtx PlanBuilderContext) api.Plan { | ||
var plan api.Plan | ||
|
||
// Check for members in failed state. | ||
for _, m := range status.Members.AsListInGroup(api.ServerGroupGateways) { | ||
inv, err := r.getGatewayInventoryConfig(ctx, planCtx, m.Group, m.Member) | ||
if err != nil { | ||
if c, ok := m.Member.Conditions.Get(api.ConditionTypeGatewayConfig); !ok || c.Status == core.ConditionTrue { | ||
plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2("Config is not present", api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, false, "Config is not present", "Config is not present", "")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hardcoded string "Config is not present" is repeated multiple times. Consider defining a constant for this message to improve maintainability.
Suggested change
plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2("Config is not present", api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, false, "Config is not present", "Config is not present", ""))
plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2(configNotPresentMsg, api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, false, configNotPresentMsg, configNotPresentMsg, ""))
Copilot uses AI. Check for mistakes. |
||
} | ||
|
||
continue | ||
} | ||
|
||
logger.JSON("inv", inv).Info("Inventory Fetched") | ||
|
||
if c, ok := m.Member.Conditions.Get(api.ConditionTypeGatewayConfig); !ok || c.Status == core.ConditionFalse || c.Hash != inv.Configuration.Hash { | ||
plan = append(plan, sharedReconcile.UpdateMemberConditionActionV2("Config Present", api.ConditionTypeGatewayConfig, m.Group, m.Member.ID, true, "Config Present", "Config Present", inv.Configuration.Hash)) | ||
} | ||
} | ||
|
||
return plan | ||
} | ||
|
||
func (r *Reconciler) getGatewayInventoryConfig(ctx context.Context, planCtx PlanBuilderContext, group api.ServerGroup, member api.MemberStatus) (*client.Inventory, error) { | ||
serverClient, err := planCtx.GetServerClient(ctx, group, member.ID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable
Suggested change
logger := log.FromContext(ctx)
Copilot uses AI. Check for mistakes. |
||
internalClient := client.NewClient(serverClient.Connection(), logger) | ||
|
||
lCtx, c := context.WithTimeout(ctx, 500*time.Millisecond) | ||
defer c() | ||
|
||
return internalClient.Inventory(lCtx) | ||
} |