forked from openstack-k8s-operators/infra-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[redis] add client helpers and add port consts
- Loading branch information
Showing
15 changed files
with
221 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2023. | ||
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. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/helper" | ||
"github.com/openstack-k8s-operators/lib-common/modules/common/util" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// IsReady - returns true if service is ready to serve requests | ||
func (instance Redis) IsReady() bool { | ||
return instance.Status.Conditions.IsTrue(condition.ReadyCondition) | ||
} | ||
|
||
// RbacConditionsSet - set the conditions for the rbac object | ||
func (instance Redis) RbacConditionsSet(c *condition.Condition) { | ||
instance.Status.Conditions.Set(c) | ||
} | ||
|
||
// RbacNamespace - return the namespace | ||
func (instance Redis) RbacNamespace() string { | ||
return instance.Namespace | ||
} | ||
|
||
// RbacResourceName - return the name to be used for rbac objects (serviceaccount, role, rolebinding) | ||
func (instance Redis) RbacResourceName() string { | ||
return "redis-" + instance.Name | ||
} | ||
|
||
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks) | ||
func SetupDefaults() { | ||
// Acquire environmental defaults and initialize Redis defaults with them | ||
redisDefaults := RedisDefaults{ | ||
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_INFRA_REDIS_IMAGE_URL_DEFAULT", RedisContainerImage), | ||
} | ||
|
||
SetupRedisDefaults(redisDefaults) | ||
} | ||
|
||
// GetRedisServerListString - return the redis servers as comma separated list | ||
// to be used in OpenStack config. | ||
func (instance *Redis) GetRedisServerListString() string { | ||
return strings.Join(instance.Status.ServerList, ",") | ||
} | ||
|
||
// GetRedisTLSSupport - return the TLS support of the redis instance | ||
func (instance *Redis) GetRedisTLSSupport() bool { | ||
return instance.Status.TLSSupport | ||
} | ||
|
||
// GetRedisByName - gets the Redis instance | ||
func GetRedisByName( | ||
ctx context.Context, | ||
h *helper.Helper, | ||
name string, | ||
namespace string, | ||
) (*Redis, error) { | ||
redis := &Redis{} | ||
err := h.GetClient().Get( | ||
ctx, | ||
types.NamespacedName{ | ||
Name: name, | ||
Namespace: namespace, | ||
}, | ||
redis) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return redis, err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
package redis | ||
|
||
const ( | ||
// RedisPort - | ||
RedisPort int32 = 6379 | ||
// SentinelPort - | ||
SentinelPort int32 = 26379 | ||
// ClusterInternalDomain - cluster internal dns domain | ||
ClusterInternalDomain = "cluster.local" | ||
) |
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
Oops, something went wrong.