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

Set environment variable for obagent to overwrite host ip config #605

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 internal/const/obagent/obagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ See the Mulan PSL v2 for more details.

package monitor

const (
LocalHostAddress = "127.0.0.1"
)

const (
HttpPort = 8088
PprofPort = 8089
Expand Down Expand Up @@ -42,6 +46,7 @@ const (
EnvMonitorUser = "MONITOR_USER"
EnvMonitorPASSWORD = "MONITOR_PASSWORD"
EnvOBMonitorStatus = "OB_MONITOR_STATUS"
EnvHostIp = "HOST_IP"
)

const (
Expand Down
29 changes: 27 additions & 2 deletions internal/resource/observer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,33 @@ func (m *OBServerManager) createMonitorContainer(obcluster *v1alpha1.OBCluster)
},
},
}

mode, modeAnnoExist := resourceutils.GetAnnotationField(m.OBServer, oceanbaseconst.AnnotationsMode)
if modeAnnoExist {
switch mode {
case oceanbaseconst.ModeStandalone:
envHostIp := corev1.EnvVar{
Name: obagentconst.EnvHostIp,
Value: obagentconst.LocalHostAddress,
}
env = append(env, envHostIp)
case oceanbaseconst.ModeService:
svc, err := m.getSvc()
if err != nil {
if kubeerrors.IsNotFound(err) {
m.Logger.Info("Svc not found")
} else {
m.Logger.Error(err, "Failed to get svc")
}
} else {
envHostIp := corev1.EnvVar{
Name: obagentconst.EnvHostIp,
Value: svc.Spec.ClusterIP,
}
env = append(env, envHostIp)
}
}
}
env = append(env, envOBModuleStatus)
env = append(env, envClusterName)
env = append(env, envClusterId)
Expand Down Expand Up @@ -540,7 +567,6 @@ func (m *OBServerManager) createOBServerContainer(obcluster *v1alpha1.OBCluster)
Name: "ZONE_NAME",
Value: m.OBServer.Spec.Zone,
}

mode, modeAnnoExist := resourceutils.GetAnnotationField(m.OBServer, oceanbaseconst.AnnotationsMode)
if modeAnnoExist {
switch mode {
Expand All @@ -567,7 +593,6 @@ func (m *OBServerManager) createOBServerContainer(obcluster *v1alpha1.OBCluster)
}
}
}

startupParameters := make([]string, 0)
for _, parameter := range obcluster.Spec.Parameters {
reserved := false
Expand Down
Loading