mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Merge branch 'main' of github.com:1Password/onepassword-operator into pass-labels-and-annotations
This commit is contained in:
4
Makefile
4
Makefile
@@ -20,12 +20,12 @@ test/coverage: ## Run test suite with coverage report
|
|||||||
go test -v ./... -cover
|
go test -v ./... -cover
|
||||||
|
|
||||||
build: ## Build operator Docker image
|
build: ## Build operator Docker image
|
||||||
@docker build -f Dockerfile --build-arg operator_version=$(curVersion) -t $(DOCKER_IMG_TAG)
|
@docker build -f Dockerfile --build-arg operator_version=$(curVersion) -t $(DOCKER_IMG_TAG) .
|
||||||
@echo "Successfully built and tagged image."
|
@echo "Successfully built and tagged image."
|
||||||
@echo "Tag: $(DOCKER_IMG_TAG)"
|
@echo "Tag: $(DOCKER_IMG_TAG)"
|
||||||
|
|
||||||
build/local: ## Build local version of the operator Docker image
|
build/local: ## Build local version of the operator Docker image
|
||||||
@docker build -f Dockerfile -t local/$(DOCKER_IMG_TAG)
|
@docker build -f Dockerfile -t local/$(DOCKER_IMG_TAG) .
|
||||||
|
|
||||||
build/binary: clean ## Build operator binary
|
build/binary: clean ## Build operator binary
|
||||||
@mkdir -p dist
|
@mkdir -p dist
|
||||||
|
@@ -84,9 +84,9 @@ An sample Deployment yaml can be found at `/deploy/operator.yaml`.
|
|||||||
|
|
||||||
To further configure the 1Password Kubernetes Operator the Following Environment variables can be set in the operator yaml:
|
To further configure the 1Password Kubernetes Operator the Following Environment variables can be set in the operator yaml:
|
||||||
|
|
||||||
- **WATCH_NAMESPACE:** comma separated list of what Namespaces to watch for changes.
|
|
||||||
- **OP_CONNECT_HOST** (required): Specifies the host name within Kubernetes in which to access the 1Password Connect.
|
- **OP_CONNECT_HOST** (required): Specifies the host name within Kubernetes in which to access the 1Password Connect.
|
||||||
- **POLLING_INTERVAL** (default: 600)**:** The number of seconds the 1Password Kubernetes Operator will wait before checking for updates from 1Password Connect.
|
- **WATCH_NAMESPACE:** (default: watch all namespaces): Comma separated list of what Namespaces to watch for changes.
|
||||||
|
- **POLLING_INTERVAL** (default: 600): The number of seconds the 1Password Kubernetes Operator will wait before checking for updates from 1Password Connect.
|
||||||
- **MANAGE_CONNECT** (default: false): If set to true, on deployment of the operator, a default configuration of the OnePassword Connect Service will be deployed to the `default` namespace.
|
- **MANAGE_CONNECT** (default: false): If set to true, on deployment of the operator, a default configuration of the OnePassword Connect Service will be deployed to the `default` namespace.
|
||||||
- **AUTO_RESTART** (default: false): If set to true, the operator will restart any deployment using a secret from 1Password Connect. This can be overwritten by namespace, deployment, or individual secret. More details on AUTO_RESTART can be found in the ["Configuring Automatic Rolling Restarts of Deployments"](#configuring-automatic-rolling-restarts-of-deployments) section.
|
- **AUTO_RESTART** (default: false): If set to true, the operator will restart any deployment using a secret from 1Password Connect. This can be overwritten by namespace, deployment, or individual secret. More details on AUTO_RESTART can be found in the ["Configuring Automatic Rolling Restarts of Deployments"](#configuring-automatic-rolling-restarts-of-deployments) section.
|
||||||
|
|
||||||
|
@@ -83,9 +83,11 @@ func main() {
|
|||||||
|
|
||||||
printVersion()
|
printVersion()
|
||||||
|
|
||||||
namespace, err := k8sutil.GetWatchNamespace()
|
namespace := os.Getenv(k8sutil.WatchNamespaceEnvVar)
|
||||||
|
|
||||||
|
deploymentNamespace, err := k8sutil.GetOperatorNamespace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err, "Failed to get watch namespace")
|
log.Error(err, "Failed to get namespace")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +141,7 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
connectStarted := false
|
connectStarted := false
|
||||||
for connectStarted == false {
|
for connectStarted == false {
|
||||||
err := op.SetupConnect(mgr.GetClient())
|
err := op.SetupConnect(mgr.GetClient(), deploymentNamespace)
|
||||||
// Cache Not Started is an acceptable error. Retry until cache is started.
|
// Cache Not Started is an acceptable error. Retry until cache is started.
|
||||||
if err != nil && !errors.Is(err, &cache.ErrCacheNotStarted{}) {
|
if err != nil && !errors.Is(err, &cache.ErrCacheNotStarted{}) {
|
||||||
log.Error(err, "")
|
log.Error(err, "")
|
||||||
|
@@ -2,7 +2,6 @@ apiVersion: apps/v1
|
|||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: onepassword-connect
|
name: onepassword-connect
|
||||||
namespace: default
|
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
@@ -2,7 +2,6 @@ apiVersion: v1
|
|||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: onepassword-connect
|
name: onepassword-connect
|
||||||
namespace: default
|
|
||||||
spec:
|
spec:
|
||||||
type: NodePort
|
type: NodePort
|
||||||
selector:
|
selector:
|
||||||
|
@@ -2,6 +2,7 @@ package onepassword
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
@@ -17,13 +18,13 @@ var logConnectSetup = logf.Log.WithName("ConnectSetup")
|
|||||||
var deploymentPath = "deploy/connect/deployment.yaml"
|
var deploymentPath = "deploy/connect/deployment.yaml"
|
||||||
var servicePath = "deploy/connect/service.yaml"
|
var servicePath = "deploy/connect/service.yaml"
|
||||||
|
|
||||||
func SetupConnect(kubeClient client.Client) error {
|
func SetupConnect(kubeClient client.Client, deploymentNamespace string) error {
|
||||||
err := setupService(kubeClient, servicePath)
|
err := setupService(kubeClient, servicePath, deploymentNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setupDeployment(kubeClient, deploymentPath)
|
err = setupDeployment(kubeClient, deploymentPath, deploymentNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -31,22 +32,22 @@ func SetupConnect(kubeClient client.Client) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupDeployment(kubeClient client.Client, deploymentPath string) error {
|
func setupDeployment(kubeClient client.Client, deploymentPath string, deploymentNamespace string) error {
|
||||||
existingDeployment := &appsv1.Deployment{}
|
existingDeployment := &appsv1.Deployment{}
|
||||||
|
|
||||||
// check if deployment has already been created
|
// check if deployment has already been created
|
||||||
err := kubeClient.Get(context.Background(), types.NamespacedName{Name: "onepassword-connect", Namespace: "default"}, existingDeployment)
|
err := kubeClient.Get(context.Background(), types.NamespacedName{Name: "onepassword-connect", Namespace: deploymentNamespace}, existingDeployment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
logConnectSetup.Info("No existing Connect deployment found. Creating Deployment")
|
logConnectSetup.Info("No existing Connect deployment found. Creating Deployment")
|
||||||
return createDeployment(kubeClient, deploymentPath)
|
return createDeployment(kubeClient, deploymentPath, deploymentNamespace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDeployment(kubeClient client.Client, deploymentPath string) error {
|
func createDeployment(kubeClient client.Client, deploymentPath string, deploymentNamespace string) error {
|
||||||
deployment, err := getDeploymentToCreate(deploymentPath)
|
deployment, err := getDeploymentToCreate(deploymentPath, deploymentNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -59,12 +60,16 @@ func createDeployment(kubeClient client.Client, deploymentPath string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeploymentToCreate(deploymentPath string) (*appsv1.Deployment, error) {
|
func getDeploymentToCreate(deploymentPath string, deploymentNamespace string) (*appsv1.Deployment, error) {
|
||||||
f, err := os.Open(deploymentPath)
|
f, err := os.Open(deploymentPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
deployment := &appsv1.Deployment{}
|
deployment := &appsv1.Deployment{
|
||||||
|
ObjectMeta: v1.ObjectMeta{
|
||||||
|
Namespace: deploymentNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
err = yaml.NewYAMLOrJSONDecoder(f, 4096).Decode(deployment)
|
err = yaml.NewYAMLOrJSONDecoder(f, 4096).Decode(deployment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -73,26 +78,30 @@ func getDeploymentToCreate(deploymentPath string) (*appsv1.Deployment, error) {
|
|||||||
return deployment, nil
|
return deployment, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupService(kubeClient client.Client, servicePath string) error {
|
func setupService(kubeClient client.Client, servicePath string, deploymentNamespace string) error {
|
||||||
existingService := &corev1.Service{}
|
existingService := &corev1.Service{}
|
||||||
|
|
||||||
//check if service has already been created
|
//check if service has already been created
|
||||||
err := kubeClient.Get(context.Background(), types.NamespacedName{Name: "onepassword-connect", Namespace: "default"}, existingService)
|
err := kubeClient.Get(context.Background(), types.NamespacedName{Name: "onepassword-connect", Namespace: deploymentNamespace}, existingService)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.IsNotFound(err) {
|
if errors.IsNotFound(err) {
|
||||||
logConnectSetup.Info("No existing Connect service found. Creating Service")
|
logConnectSetup.Info("No existing Connect service found. Creating Service")
|
||||||
return createService(kubeClient, servicePath)
|
return createService(kubeClient, servicePath, deploymentNamespace)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func createService(kubeClient client.Client, servicePath string) error {
|
func createService(kubeClient client.Client, servicePath string, deploymentNamespace string) error {
|
||||||
f, err := os.Open(servicePath)
|
f, err := os.Open(servicePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
service := &corev1.Service{}
|
service := &corev1.Service{
|
||||||
|
ObjectMeta: v1.ObjectMeta{
|
||||||
|
Namespace: deploymentNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
err = yaml.NewYAMLOrJSONDecoder(f, 4096).Decode(service)
|
err = yaml.NewYAMLOrJSONDecoder(f, 4096).Decode(service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -25,7 +25,7 @@ func TestServiceSetup(t *testing.T) {
|
|||||||
// Create a fake client to mock API calls.
|
// Create a fake client to mock API calls.
|
||||||
client := fake.NewFakeClientWithScheme(s, objs...)
|
client := fake.NewFakeClientWithScheme(s, objs...)
|
||||||
|
|
||||||
err := setupService(client, "../../deploy/connect/service.yaml")
|
err := setupService(client, "../../deploy/connect/service.yaml", defaultNamespacedName.Namespace)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error Setting Up Connect: %v", err)
|
t.Errorf("Error Setting Up Connect: %v", err)
|
||||||
@@ -50,7 +50,7 @@ func TestDeploymentSetup(t *testing.T) {
|
|||||||
// Create a fake client to mock API calls.
|
// Create a fake client to mock API calls.
|
||||||
client := fake.NewFakeClientWithScheme(s, objs...)
|
client := fake.NewFakeClientWithScheme(s, objs...)
|
||||||
|
|
||||||
err := setupDeployment(client, "../../deploy/connect/deployment.yaml")
|
err := setupDeployment(client, "../../deploy/connect/deployment.yaml", defaultNamespacedName.Namespace)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error Setting Up Connect: %v", err)
|
t.Errorf("Error Setting Up Connect: %v", err)
|
||||||
|
Reference in New Issue
Block a user